1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
| <script type="text/javascript">
dojo.require('dojox.grid.EnhancedGrid');
dojo.require('dojox.grid.enhanced.plugins.DnD');
dojo.require('dijit.form.Button');
var
cmsAdminCmsDocumentStore,
cmsAdminCmsDocumentGrid,
cmsAdminCmsDocumentGridHandler,
cmsAdminCmsDocumentDialog;
dojo.declare('clientCmsAdminCmsDocument.data.ItemFileWriteStore', dojo.data.ItemFileWriteStore, {
clearOnClose: true,
save: function(saveCompleteCallback, saveFailedCallback) {
var
i, data, itemData;
// Modified Items
data = [];
for (i in this._pending._modifiedItems) {
item = this._itemsByIdentity[i];
itemData = {};
dojo.forEach(this.getAttributes(item), dojo.hitch(this, function(attribute){
itemData[attribute] = this.getValue(item, attribute);
}));
data.push(itemData);
}
if (data.length > 0) {
dojo.xhrPost({
url: this.url,
content: {
sf_method: 'put',
data: dojo.toJson(data)
}
});
}
// Deleted Items
data = [];
for (i in this._pending._deletedItems) {
itemData = {id: i};
data.push(itemData);
}
if (data.length > 0) {
dojo.xhrPost({
url: this.url,
content: {
sf_method: 'delete',
data: dojo.toJson(data),
}
});
}
}
});
cmsAdminCmsDocumentStore = new clientCmsAdminCmsDocument.data.ItemFileWriteStore({
url: '<?php echo url_for('cms_admin_cms_document_store', array('cms_module_id' => $cms_module->id)) ?>'
});
cmsAdminCmsDocumentGrid = new dojox.grid.EnhancedGrid(
{
store: cmsAdminCmsDocumentStore,
rowSelector: '20px',
selectionMode: 'single',
canSort: false,
plugins: {
dnd: {
dndConfig: {
col: false,
cell: false,
in: false,
out: false
}
}
},
structure: [{
defaultCell: {
width: 'auto'
},
rows: [
{
field: 'label',
name: 'Label'
},
{
field: 'is_active',
name: 'Actif',
width: '40px',
formatter: function(value) {
return value ? '<?php echo image_tag('/cmsPlugin/images/icons/is_active_small.png') ?>' : '';
}
},
{
name: 'Actions',
field: '_item',
width: '90px',
formatter: function(item) {
return new dijit.form.Button({
label: 'Supprimer',
onClick: function() {
cmsAdminDialogConfirmation(function(){
cmsAdminCmsDocumentStore.deleteItem(item);
cmsAdminCmsDocumentStore.save();
});
}
});
}
}
]
}],
onRowDblClick: function(event) {
cmsAdminCmsDocumentDialog.set('title', 'Document - ' + this.store.getValue(this.getItem(event.rowIndex), 'label'));
cmsAdminCmsDocumentDialog.set('href', this.store.getValue(this.getItem(event.rowIndex), 'cms_admin_update_url'));
cmsAdminCmsDocumentDialog.show();
}
},
'cms_admin_cms_document_grid'
);
cmsAdminCmsDocumentDialog= new dijit.Dialog({}, 'cms_admin_cms_document_dialog');
if (!cmsAdminCmsDocumentGridHandler) {
cmsAdminCmsDocumentGridHandler = dojo.subscribe('dojox/grid/rearrange/move/cms_admin_cms_document_grid', cmsAdminCmsDocumentGrid, function(type, mapping){
// Re-order items by position
var i;
for (i=0; i<this.rowCount; i++) {
this.store.setValue(this.getItem(i), 'position', i + 1);
}
this.store.save();
});
}
</script> |
Partager