wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
dialog.js.php
Go to the documentation of this file.
1 /**
2  * @class AssociateDialog. Build on Ext.LayoutDialog
3  */
4 AssociateDialog = function() {};
5 
6 AssociateDialog.prototype = {
7  // the Ext.LayoutDialog instance
8  dialog: null,
9  // the wcmf.grid.Grid instance
10  grid: null,
11  // the source Grid instance
12  sourceGrid: null,
13  // the oid of the node to associate to
14  oid: null,
15  // the role of the associated nodes
16  associateAs: '',
17  // need a complete refresh after associate action?
18  needPageRefresh: false,
19 
20  /**
21  * Show the dialog
22  * @param id The html container id
23  * @param type The type to display
24  * @param sourceGrid The grid from which the dialog is opened
25  * @param oid The oid of the node to associate to
26  * @param associateAs The role of the associated nodes as seen from oid: Either 'parent' or 'child'
27  * @param needPageRefresh True/False wether the whole page must be reloaded after the action or not
28  */
29  show: function(type, sourceGrid, oid, associateAs, needPageRefresh) {
30  if (!this.dialog) {
31  // initialize the grid
32  this.grid = new wcmf.grid.Grid();
33  // copy column defs
34  var columnDefs = [];
35  for (var i=0; i<sourceGrid.columnDefs.length; i++)
36  {
37  var origCol = sourceGrid.columnDefs[i];
38  columnDefs.push({id:origCol.id, dataIndex:origCol.dataIndex, header:origCol.header, width:origCol.width,
39  sortable:origCol.sortable, renderer:this.grid.renderColumnDefault.createDelegate(this.grid)});
40  }
41  this.grid.init('', type, '', columnDefs, {paging:true, singleSelect:false}, []);
42  var extGrid = this.grid.getGridImpl();
43 
44  // add listeners
45  var selModel = extGrid.getSelectionModel();
46  selModel.on('selectionchange', this.selectionChanged.createDelegate(this));
47 
48  var dlg = new Ext.Window({
49  applyTo:Ext.DomHelper.append(document.body, {tag:'div'}),
50  layout:'fit',
51  width:500,
52  height:300,
53  closeAction:'hide',
54  plain:true,
55  items:extGrid,
56  buttons: [{
57  text:'Submit',
58  handler: this.submitDlg.createDelegate(this),
59  disabled:true
60  },{
61  text: 'Close',
62  handler: function() {
63  dlg.hide();
64  }
65  }]
66  });
67 
68  this.dialog = dlg;
69  this.sourceGrid = sourceGrid;
70  this.oid = oid;
71  this.associateAs = associateAs;
72  this.needPageRefresh = needPageRefresh;
73 
74  extGrid.un("celldblclick", this.grid.cellDblClicked, this.grid);
75  extGrid.on("celldblclick", this.submitDlg, this);
76  }
77  this.grid.load();
78  this.grid.getGridImpl().getSelectionModel().clearSelections();
79  this.dialog.show();
80  },
81 
82  selectionChanged: function(selModel) {
83  var buttons = this.dialog.buttons;
84  for (var i=0; i<buttons.length; i++) {
85  if (buttons[i].getText() == 'Submit') {
86  if (selModel.getCount() > 0)
87  buttons[i].enable();
88  else
89  buttons[i].disable();
90  break;
91  }
92  }
93  },
94 
95  submitDlg: function() {
96  document.body.style.cursor = "wait";
97  var records = this.grid.getGridImpl().getSelectionModel().getSelections();
98  var ids = '';
99  if (records.length > 0) {
100  for (var i=0; i<records.length-1; i++)
101  ids += records[i].id+",";
102  ids += records[records.length-1].id;
103  }
104  Action.perform('associate', {oid:this.oid, associateoids:ids, associateAs:this.associateAs}, this.actionPerformed, this);
105  },
106 
107  /**
108  * Callback
109  */
110  actionPerformed: function(record, arg, success) {
111  document.body.style.cursor = "";
112  if (this.needPageRefresh)
113  submitAction('');
114  else {
115  this.sourceGrid.load();
116  this.dialog.hide();
117  }
118  }
119 }