GoodNews.grid.Subscribers = function(config){
config = config || {};
Ext.applyIf(config,{
id: 'goodnews-grid-subscribers'
,url: GoodNews.config.connectorUrl
,baseParams: { action: 'mgr/subscribers/getList' }
,fields: [
'id'
,'username'
,'fullname'
,'email'
,'newslettercategories'
,'extended'
,'menu'
]
,emptyText: _('goodnews.subscribers_none')
,paging: true
,remoteSort: true
,columns: [{
header: _('goodnews.subscriber_username')
,dataIndex: 'username'
,sortable: true
,width: 100
},{
header: _('goodnews.subscriber_fullname')
,dataIndex: 'fullname'
,sortable: true
,width: 100
},{
header: _('goodnews.subscriber_email')
,dataIndex: 'email'
,sortable: true
,width: 100
},{
header: _('goodnews.subscriber_categories')
,dataIndex: 'newslettercategories'
,width: 100
},{
header: 'Extended (debug)'
,dataIndex: 'extended'
,width: 100
}]
,tbar:['->',{
xtype: 'modx-combo-usergroup'
,name: 'usergroup'
,id: 'goodnews-user-filter-usergroup'
,itemId: 'usergroup'
,emptyText: _('goodnews.subscribers_user_group')+'...'
,baseParams: {
action: 'getList'
,addAll: true
}
,value: MODx.request['usergroup'] ? MODx.request['usergroup'] : ''
,width: 200
,listeners: {
'select': {fn:this.filterUsergroup,scope:this}
}
},'-',{
xtype: 'textfield'
,id: 'goodnews-subscribers-search-filter'
,emptyText: _('goodnews.subscribers_search...')
,listeners: {
'change': {fn:this.search,scope:this}
,'render': {fn: function(cmp) {
new Ext.KeyMap(cmp.getEl(), {
key: Ext.EventObject.ENTER
,fn: function() {
this.fireEvent('change',this);
this.blur();
return true;
}
,scope: cmp
});
},scope:this}
}
},{
xtype: 'button'
,id: 'goodnews-subscribers-filter-clear'
,text: _('filter_clear')
,listeners: {
'click': {fn: this.clearFilter,scope:this}
}
}]
});
GoodNews.grid.Subscribers.superclass.constructor.call(this,config);
};
Ext.extend(GoodNews.grid.Subscribers,MODx.grid.Grid,{
getMenu: function() {
var r = this.getSelectionModel().getSelected();
var p = r.data.perm;
return [{
text: _('goodnews.subscriber_update')
,handler: this.updateSubscriber
},'-',{
text: _('goodnews.user_update')
,handler: this.updateUser
}];
}
,updateSubscriber: function(btn,e) {
//needs to be destroyed in order to recreate checkboxgroup!
if (this.updateSubscriberWindow) {
this.updateSubscriberWindow.destroy();
}
this.updateSubscriberWindow = MODx.load({
xtype: 'goodnews-window-subscriber-update'
,record: this.menu.record
,scope: this
,listeners: {
'success': {fn:this.refresh,scope:this}
}
});
this.updateSubscriberWindow.setValues(this.menu.record);
this.updateSubscriberWindow.show(e.target);
}
,updateUser: function(btn,e) {
location.href = 'index.php?a='+MODx.action['security/user/update']+'&id='+this.menu.record.id;
}
,filterUsergroup: function(cb,nv,ov) {
this.getStore().baseParams.usergroup = Ext.isEmpty(nv) || Ext.isObject(nv) ? cb.getValue() : nv;
this.getBottomToolbar().changePage(1);
this.refresh();
return true;
}
,search: function(tf,nv,ov) {
var s = this.getStore();
s.baseParams.query = tf.getValue();
this.getBottomToolbar().changePage(1);
this.refresh();
}
,clearFilter: function() {
this.getStore().baseParams = {
action: 'mgr/subscribers/getList'
};
Ext.getCmp('goodnews-subscribers-search-filter').reset();
Ext.getCmp('goodnews-user-filter-usergroup').reset();
this.getBottomToolbar().changePage(1);
}
});
Ext.reg('goodnews-grid-subscribers',GoodNews.grid.Subscribers);
GoodNews.window.UpdateSubscriber = function(config) {
config = config || {};
console.log(this);
Ext.applyIf(config,{
title: _('goodnews.subscriber_update')
,url: GoodNews.config.connectorUrl
,baseParams: {
action: 'mgr/subscribers/update'
}
,fields: [{
xtype: 'hidden'
,name: 'id'
},{
xtype: 'displayfield'
,fieldLabel: 'extended field'
,name: 'extended'
,readOnly: true
},{
xtype: 'displayfield'
,fieldLabel: _('goodnews.subscriber_username')
,name: 'username'
,readOnly: true
},{
id: 'cat-ext-checkboxgroup'
,fieldLabel: _('goodnews.subscriber_categories')
,name: 'newslettercategories'
,listeners: {
'render': {
fn: function() {
catCheckboxGroup('cat-ext-checkboxgroup','newslettercategories');
}
}
}
}]
});
GoodNews.window.UpdateSubscriber.superclass.constructor.call(this,config);
};
Ext.extend(GoodNews.window.UpdateSubscriber,MODx.Window);
Ext.reg('goodnews-window-subscriber-update',GoodNews.window.UpdateSubscriber);
This function generates the checkbox group. The problem is, I don't know how to match the list of categories (mgr/category/getList) with the list of categories the user has already in his extended fields - to set the corresponding checkboxes to checked.
function catCheckboxGroup(renderTarget,groupName) {
Ext.onReady(function() {
var catStore = new Ext.data.JsonStore({
url: GoodNews.config.connectorUrl
,baseParams: {
action: 'mgr/category/getList'
}
,fields: ['id','name','uniquekey']
,root: 'results'
,autoLoad: false
,autoDestroy: true
,listeners: {
'load': {
fn: function(t, records, options, success) {
var catArray = [];
for (var i=0; i<records.length; i++) {
catArray.push({
name: groupName+'['+records[i].data.uniquekey+']'
,inputValue: records[i].data.id
,boxLabel: records[i].data.name
});
}
var catCheckboxGroup = new Ext.form.CheckboxGroup({
items: catArray
,columns: 2
,renderTo: renderTarget
});
//console.log(catArray);
}
}
/*,'loadexception': {
fn: function(obj, options, response, e){
console.info('store loadexception, arguments:', arguments);
console.info('error = ', e);
}
}*/
}
});
catStore.load();
});
};