Skip to content

Commit

Permalink
Add calendar synchronization list
Browse files Browse the repository at this point in the history
Impove JS code
  • Loading branch information
diorcety committed Sep 1, 2011
1 parent ab501b8 commit 5c0fd63
Show file tree
Hide file tree
Showing 10 changed files with 329 additions and 20 deletions.
43 changes: 36 additions & 7 deletions AddressBookGrid.js
Expand Up @@ -29,23 +29,51 @@ GO.zpush.AddressBookGrid = function(config) {
root: 'results',
id: 'id',
totalProperty:'total',
fields: ['id','name','synchronize','default']
fields: [
{name: 'id', type: 'integer'},
{name: 'name', type: 'string'},
{name: 'synchronize', type: 'boolean'},
{name: 'default', type: 'boolean'}
]
});

var synchronizeColumn = new GO.grid.CheckColumn({
header: GO.zpush.lang.addressBookGrid.columns.synchronize,
dataIndex: 'synchronize',
width: 120
disabled_field: 'default',
width: 120,
sortable: false,
menuDisabled: true,
renderer : function(v, p, record) {
p.css += ' x-grid3-check-col-td';

var disabled = record.get(this.disabled_field);

var on;
if (disabled) {
on = '-on x-item-disabled';
} else {
if (!GO.util.empty(v)) {
on = '-on';
} else {
on = '';
}
}

return '<div class="x-grid3-check-col' + on + ' x-grid3-cc-' + this.id + '">&#160;</div>';
}
});
var defaultColumn = new GO.grid.RadioColumn({
header: GO.zpush.lang.addressBookGrid.columns['default'],
dataIndex: 'default',
width: 120
width: 120,
sortable: false,
menuDisabled: true
});
/*
* ColumnModel used by our DeviceGrid
*/
var ElementModel = new Ext.grid.ColumnModel(
var AddressBookModel = new Ext.grid.ColumnModel(
[
{
header: GO.zpush.lang.addressBookGrid.columns.name,
Expand All @@ -55,14 +83,15 @@ GO.zpush.AddressBookGrid = function(config) {
cell.css = "readonlycell";
return value;
},
width: 120
width: 120,
sortable: false
},
synchronizeColumn,
defaultColumn
]
);
ElementModel.defaultSortable = true;
config.cm = ElementModel;
AddressBookModel.defaultSortable = true;
config.cm = AddressBookModel;

config.view = new Ext.grid.GridView({
emptyText: GO.lang['strNoItems']
Expand Down
162 changes: 162 additions & 0 deletions CalendarGrid.js
@@ -0,0 +1,162 @@
// Creates a namespace to be used for scoping variables and classes
Ext.namespace('GO.z-push');

/*
* This is the constructor of our PresidentsGrid
*/
GO.zpush.CalendarGrid = function(config) {

if (!config) {
config = {};
}

config.autoScroll = true;

config.store = new GO.data.JsonStore({
/*
* Here we store our remotely-loaded JSON data from json.php?task=devices
*/
url: GO.settings.modules['z-push'].url + 'json.php',
baseParams: {
task: 'calendars'
},
autoSave : false,
writer: new Ext.data.JsonWriter({
encode: true,
writeAllFields: true,
listful: true
}),
root: 'results',
id: 'id',
totalProperty:'total',
fields: [
{name: 'id', type: 'integer'},
{name: 'name', type: 'string'},
{name: 'synchronize', type: 'boolean'},
{name: 'default', type: 'boolean'}
]
});

var synchronizeColumn = new GO.grid.CheckColumn({
header: GO.zpush.lang.calendarGrid.columns.synchronize,
dataIndex: 'synchronize',
disabled_field: 'default',
width: 120,
sortable: false,
menuDisabled: true,
renderer : function(v, p, record) {
p.css += ' x-grid3-check-col-td';

var disabled = record.get(this.disabled_field);

var on;
if (disabled) {
on = '-on x-item-disabled';
} else {
if (!GO.util.empty(v)) {
on = '-on';
} else {
on = '';
}
}

return '<div class="x-grid3-check-col' + on + ' x-grid3-cc-' + this.id + '">&#160;</div>';
}
});
var defaultColumn = new GO.grid.RadioColumn({
header: GO.zpush.lang.calendarGrid.columns['default'],
dataIndex: 'default',
width: 120,
sortable: false,
menuDisabled: true
});
/*
* ColumnModel used by our DeviceGrid
*/
var CalendarModel = new Ext.grid.ColumnModel(
[
{
header: GO.zpush.lang.calendarGrid.columns.name,
readOnly: true,
dataIndex: 'name',
renderer: function(value, cell) {
cell.css = "readonlycell";
return value;
},
width: 120,
sortable: true
},
synchronizeColumn,
defaultColumn
]
);
CalendarModel.defaultSortable = true;
config.cm = CalendarModel;

config.view = new Ext.grid.GridView({
emptyText: GO.lang['strNoItems']
});

config.plugins = [synchronizeColumn, defaultColumn];
config.loadMask = true;

config.tbar = [
{
itemId: 'refresh',
xtype: 'button',
text: GO.zpush.lang.calendarGrid.buttons.refresh,
iconCls: 'btn-refresh',
scope: this,
handler: function(btn) {
this.store.load();
}
},
{
xtype: 'tbseparator'
},
{
itemId: 'save',
xtype: 'button',
text: GO.zpush.lang.calendarGrid.buttons.save,
iconCls: 'btn-save',
scope: this,
handler: function(btn) {
this.store.save();
}
}
];


/*
* explicitly call the superclass constructor
*/
GO.zpush.CalendarGrid.superclass.constructor.call(this, config);

};

/*
* Extend the base class
*/
Ext.extend(GO.zpush.CalendarGrid, GO.grid.GridPanel, {

loaded : false,

afterRender : function() {
GO.zpush.CalendarGrid.superclass.afterRender.call(this);

if (this.isVisible()) {
this.onGridShow();
}
},

onGridShow : function() {
if (!this.loaded && this.rendered) {
this.store.load();
this.loaded = true;
}
}

});



11 changes: 9 additions & 2 deletions DeviceGrid.js
Expand Up @@ -11,7 +11,7 @@ GO.zpush.DeviceGrid = function(config) {
}

config.autoScroll = true;

config.store = new GO.data.JsonStore({
/*
* Here we store our remotely-loaded JSON data from json.php?task=devices
Expand All @@ -23,7 +23,14 @@ GO.zpush.DeviceGrid = function(config) {
root: 'results',
id: 'id',
totalProperty:'total',
fields: ['id','device','agent','first_sync','last_sync','status']
fields: [
{name: 'id', type: 'string'},
{name: 'device', type: 'string'},
{name: 'agent', type: 'string'},
{name: 'first_sync', type: 'date', dateFormat: 'Y-m-d H:i:s'},
{name: 'last_sync', type: 'date', dateFormat: 'Y-m-d H:i:s'},
{name: 'status', type: 'integer'}
]
});

/*
Expand Down
5 changes: 5 additions & 0 deletions MainPanel.js
Expand Up @@ -10,6 +10,10 @@ GO.zpush.MainPanel = function(config) {
}

config.items = [
new GO.zpush.CalendarGrid({
fieldLabel:GO.zpush.lang.calendarGrid.title,
height: 200
}),
new GO.zpush.AddressBookGrid({
fieldLabel:GO.zpush.lang.addressBookGrid.title,
height: 200
Expand All @@ -21,6 +25,7 @@ GO.zpush.MainPanel = function(config) {
];
config.padding = 10;
config.labelWidth = 200;
config.autoScroll = true;

GO.zpush.MainPanel.superclass.constructor.call(this, config);
};
Expand Down
37 changes: 36 additions & 1 deletion classes/zpush.class.inc.php
Expand Up @@ -89,13 +89,48 @@ function getAddressBooks($userid)

function addAddressBook($userid, $addressbookid)
{
return $this->query("INSERT INTO as_addressbooks (user_id, addressbook_id) VALUES (?,?)", array('i', 'i'), array($userid, $addressbookid));
return $this->query("INSERT IGNORE INTO as_addressbooks (user_id, addressbook_id) VALUES (?,?)", array('i', 'i'), array($userid, $addressbookid));
}

function removeAddressBook($userid, $addressbookid)
{
return $this->query("DELETE FROM as_addressbooks WHERE user_id=? AND addressbook_id=?", array('i', 'i'), array($userid, $addressbookid));
}

function setDefaultCalendar($userid, $calendarid)
{
return $this->query("INSERT INTO as_default_calendar (user_id, calendar_id) VALUES (?,?) ON DUPLICATE KEY UPDATE calendar_id=?", array('i', 'i', 'i'), array($userid, $calendarid, $calendarid));
}

function getDefaultCalendar($userid)
{
$this->query("SELECT calendar_id FROM as_default_calendar WHERE user_id=?", array('i'), array($userid));
$result = $this->next_record();
if ($result == null)
return null;
return $result['calendar_id'];
}

function getCalendars($userid)
{
$this->query("SELECT calendar_id FROM as_calendars WHERE user_id=?", array('i'), array($userid));
$result = Array();
while ($record = $this->next_record())
{
$result [] = $record['calendar_id'];
}
return $result;
}

function addCalendar($userid, $calendarid)
{
return $this->query("INSERT IGNORE INTO as_calendars (user_id, calendar_id) VALUES (?,?)", array('i', 'i'), array($userid, $calendarid));
}

function removeCalendar($userid, $calendarid)
{
return $this->query("DELETE FROM as_calendars WHERE user_id=? AND calendar_id=?", array('i', 'i'), array($userid, $calendarid));
}
}

?>

0 comments on commit 5c0fd63

Please sign in to comment.