diff --git a/AddressBookGrid.js b/AddressBookGrid.js index 1366daf..c43950f 100755 --- a/AddressBookGrid.js +++ b/AddressBookGrid.js @@ -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 '
 
'; + } }); 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, @@ -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'] diff --git a/CalendarGrid.js b/CalendarGrid.js new file mode 100755 index 0000000..f9b786b --- /dev/null +++ b/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 '
 
'; + } + }); + 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; + } + } + +}); + + + \ No newline at end of file diff --git a/DeviceGrid.js b/DeviceGrid.js index 1a0fb63..6a2e67b 100755 --- a/DeviceGrid.js +++ b/DeviceGrid.js @@ -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 @@ -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'} + ] }); /* diff --git a/MainPanel.js b/MainPanel.js index 40f3a62..10d0678 100755 --- a/MainPanel.js +++ b/MainPanel.js @@ -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 @@ -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); }; diff --git a/classes/zpush.class.inc.php b/classes/zpush.class.inc.php index 4fbcad4..670af61 100755 --- a/classes/zpush.class.inc.php +++ b/classes/zpush.class.inc.php @@ -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)); + } } ?> \ No newline at end of file diff --git a/json.php b/json.php index 878bbc5..4a97238 100755 --- a/json.php +++ b/json.php @@ -18,9 +18,11 @@ require_once($GO_MODULES->modules['z-push']['class_path'] . 'zpush.class.inc.php'); require_once($GO_MODULES->modules['addressbook']['class_path'] . 'addressbook.class.inc.php'); +require_once($GO_MODULES->modules['calendar']['class_path'] . 'calendar.class.inc.php'); $GO_AS = new zpush(); $GO_ADDRESSBOOK = new addressbook(); +$GO_CALENDAR = new calendar(); $task = isset($_REQUEST['task']) ? ($_REQUEST['task']) : ''; @@ -55,11 +57,13 @@ { if ($addressbook['default']) { $GO_AS->setDefaultAddressBook($GO_SECURITY->user_id, $addressbook['id']); - } - if ($addressbook['synchronize']) { - $GO_AS->addAddressBook($GO_SECURITY->user_id, $addressbook['id']); - } else { $GO_AS->removeAddressBook($GO_SECURITY->user_id, $addressbook['id']); + } else { + if ($addressbook['synchronize']) { + $GO_AS->addAddressBook($GO_SECURITY->user_id, $addressbook['id']); + } else { + $GO_AS->removeAddressBook($GO_SECURITY->user_id, $addressbook['id']); + } } } $response['success'] = true; @@ -76,7 +80,7 @@ $addressbook = array(); $addressbook['id'] = $result['id']; $addressbook['name'] = $result['name']; - $addressbook['synchronized'] = in_array($result['id'], $synchronized); + $addressbook['synchronize'] = in_array($result['id'], $synchronized); $addressbook['default'] = ($default == $result['id']) ? true : false; $response['results'][] = $addressbook; @@ -85,6 +89,48 @@ $response['success'] = true; } break; + + case 'calendars': + // Commit + if (isset($_REQUEST['results'])) { + $results = json_decode($_REQUEST['results'], true); + foreach ($results as $calendar) + { + if ($calendar['default']) { + $GO_AS->setDefaultCalendar($GO_SECURITY->user_id, $calendar['id']); + $GO_AS->removeCalendar($GO_SECURITY->user_id, $calendar['id']); + } + else { + if ($calendar['synchronize']) { + $GO_AS->addCalendar($GO_SECURITY->user_id, $calendar['id']); + } else { + $GO_AS->removeCalendar($GO_SECURITY->user_id, $calendar['id']); + } + } + } + $response['success'] = true; + } else { + $response['results'] = array(); + $synchronized = $GO_AS->getCalendars($GO_SECURITY->user_id); + $default = $GO_AS->getDefaultCalendar($GO_SECURITY->user_id); + + $GO_CALENDAR->get_user_calendars($GO_SECURITY->user_id); + while ($GO_CALENDAR->next_record()) + { + $result = $GO_CALENDAR->record; + + $calendar = array(); + $calendar['id'] = $result['id']; + $calendar['name'] = $result['name']; + $calendar['synchronize'] = in_array($result['id'], $synchronized); + $calendar['default'] = ($default == $result['id']) ? true : false; + + $response['results'][] = $calendar; + } + $response['total'] = sizeof($response['results']); + $response['success'] = true; + } + break; /* {TASKSWITCH} */ } } catch (Exception $e) diff --git a/language/en.js b/language/en.js index e286fb2..5608c44 100755 --- a/language/en.js +++ b/language/en.js @@ -33,7 +33,7 @@ GO.zpush.lang.deviceGrid.buttons.wipe = "Wipe"; GO.zpush.lang.addressBookGrid = {}; -GO.zpush.lang.addressBookGrid.title = "AddressBooks"; +GO.zpush.lang.addressBookGrid.title = "Addressbooks"; GO.zpush.lang.addressBookGrid.columns = {}; GO.zpush.lang.addressBookGrid.columns.name = "Addressbook name"; @@ -42,4 +42,16 @@ GO.zpush.lang.addressBookGrid.columns['default'] = "Default"; GO.zpush.lang.addressBookGrid.buttons = {}; GO.zpush.lang.addressBookGrid.buttons.refresh = "Refresh"; -GO.zpush.lang.addressBookGrid.buttons.save = "Save"; \ No newline at end of file +GO.zpush.lang.addressBookGrid.buttons.save = "Save"; + +GO.zpush.lang.calendarGrid = {}; +GO.zpush.lang.calendarGrid.title = "Calendars"; + +GO.zpush.lang.calendarGrid.columns = {}; +GO.zpush.lang.calendarGrid.columns.name = "Calendar name"; +GO.zpush.lang.calendarGrid.columns.synchronize = "Synchronize"; +GO.zpush.lang.calendarGrid.columns['default'] = "Default"; + +GO.zpush.lang.calendarGrid.buttons = {}; +GO.zpush.lang.calendarGrid.buttons.refresh = "Refresh"; +GO.zpush.lang.calendarGrid.buttons.save = "Save"; \ No newline at end of file diff --git a/language/fr.js b/language/fr.js index 14b21c7..1de152b 100755 --- a/language/fr.js +++ b/language/fr.js @@ -42,4 +42,16 @@ GO.zpush.lang.addressBookGrid.columns['default'] = "Défaut"; GO.zpush.lang.addressBookGrid.buttons = {}; GO.zpush.lang.addressBookGrid.buttons.refresh = "Rafraîchir"; -GO.zpush.lang.addressBookGrid.buttons.save = "Sauvegarder"; \ No newline at end of file +GO.zpush.lang.addressBookGrid.buttons.save = "Sauvegarder"; + +GO.zpush.lang.calendarGrid = {}; +GO.zpush.lang.calendarGrid.title = "Calendriers"; + +GO.zpush.lang.calendarGrid.columns = {}; +GO.zpush.lang.calendarGrid.columns.name = "Nom du calendrier"; +GO.zpush.lang.calendarGrid.columns.synchronize = "Synchroniser"; +GO.zpush.lang.calendarGrid.columns['default'] = "Défaut"; + +GO.zpush.lang.calendarGrid.buttons = {}; +GO.zpush.lang.calendarGrid.buttons.refresh = "Rafraîchir"; +GO.zpush.lang.calendarGrid.buttons.save = "Sauvegarder"; \ No newline at end of file diff --git a/lib/backend/GObackend.php b/lib/backend/GObackend.php index 9e6b42d..1e8445a 100755 --- a/lib/backend/GObackend.php +++ b/lib/backend/GObackend.php @@ -288,7 +288,7 @@ function GetWasteBasket() function GetMessageList($uri, $cutoffdate) { - $this->log("Get Message List $uri ($cutoffdate)"); + $this->log("Get Message List \"$uri\" ($cutoffdate)"); $messages = array(); if ($this->isCalendars($uri)) { diff --git a/scripts.txt b/scripts.txt index d0faec2..25e115d 100755 --- a/scripts.txt +++ b/scripts.txt @@ -1,3 +1,4 @@ modules/z-push/MainPanel.js modules/z-push/DeviceGrid.js -modules/z-push/AddressBookGrid.js \ No newline at end of file +modules/z-push/AddressBookGrid.js +modules/z-push/CalendarGrid.js \ No newline at end of file