-Gilbert.lib.plugins.models.ui.DestructionConsequencesWindow = Ext.extend(Ext.Window, {
- constructor: function (consequences, confirm_handler, cancel_handler, config) {
- var convert_consequences_array = function (consequences) {
- var last_parent = consequences[0];
- Ext.each(consequences, function (consequence, index) {
- if (index != 0) {
- if (!Ext.isArray(consequence)) {
- last_parent = consequence;
- } else {
- last_parent['children'] = convert_consequences_array(consequence);
- delete consequences[index];
- }
- }
- });
- new_consequences = [];
- Ext.each(consequences, function (consequence) {
- if (consequence) {
- var new_consequence = {};
- if (!consequence['children']) {
- new_consequence['leaf'] = true;
- } else {
- new_consequence['leaf'] = false;
- new_consequence['children'] = consequence['children'];
- }
- var app_label = consequence['app_label'];
- var name = consequence['name'];
- var model = Gilbert.get_model(app_label, name);
- if (model) {
- new_consequence['text'] = consequence['__unicode__'];
- new_consequence['iconCls'] = model.iconCls;
- } else {
- new_consequence['text'] = '(' + consequence['name'] + ') ' + consequence['__unicode__'];
- new_consequence['iconCls'] = 'icon-block';
- }
- new_consequence['disabled'] = true;
- new_consequences.push(new_consequence);
- }
- });
- return new_consequences;
- };
-
- var tree = this.tree = new Ext.tree.TreePanel({
- loader: new Ext.tree.TreeLoader(),
- enableDD: false,
- animate: false,
- trackMouseOver: false,
- autoScroll: true,
- root: {
- 'disabled': true,
- 'text': 'To be deleted',
- 'iconCls': 'icon-minus',
- 'leaf': false,
- 'children': convert_consequences_array(consequences),
- },
- useArrows: true,
- rootVisible: false,
- region: 'center',
- });
-
- Gilbert.lib.plugins.models.ui.DestructionConsequencesWindow.superclass.constructor.call(this, Ext.applyIf(config||{}, {
- layout: 'border',
- width: 300,
- height: 300,
- modal: true,
- title: 'Confirm deletion',
- iconCls: 'icon-minus',
- items: [
- {
- region: 'north',
- xtype: 'panel',
- html: 'Are you sure you want to delete these items?',
- bodyStyle: 'padding: 15px;',
- },
- tree,
- ],
- bbar: [
- {
- xtype: 'button',
- text: 'Cancel',
- handler: cancel_handler,
- },
- '->',
- {
- xtype: 'button',
- text: 'Confirm',
- handler: confirm_handler,
- },
- ],
- }));
- },
-});
-
-