comparison app/controller/grid/Status.js @ 990:c2a726887dd7

The last status can not be edited anymore. When a new status is added, the new record is preset with ALL previous variables, this includes the StatusStufe! The Date is corrected to the current date. Also the store is sorted by Datum now.
author Dustin Demuth <dustin@intevation.de>
date Wed, 16 Dec 2015 09:49:09 +0100
parents ea477f62a667
children 77ea9a5c5f1d
comparison
equal deleted inserted replaced
989:b892eb346f14 990:c2a726887dd7
19 init: function() { 19 init: function() {
20 this.control({ 20 this.control({
21 'statusgrid': { 21 'statusgrid': {
22 edit: this.gridSave, 22 edit: this.gridSave,
23 canceledit: this.cancelEdit, 23 canceledit: this.cancelEdit,
24 select: this.toggleAllowedPermissions
25 }, 24 },
26 'statusgrid button[action=add]': { 25 'statusgrid button[action=add]': {
27 click: this.add 26 click: this.add
28 } 27 }
29 }); 28 });
80 } 79 }
81 }, 80 },
82 81
83 /** 82 /**
84 * This function adds a new row to add a Status 83 * This function adds a new row to add a Status
84 * and copies the data of the previous status into the new one
85 * if possible.
85 */ 86 */
86 add: function(button) { 87 add: function(button) {
87 var record = Ext.create('Lada.model.Status', {
88 messungsId: button.up('statusgrid').recordId
89 });
90 //Set the Date
91 record.data.datum = new Date();
92 var lastrow = button.up('statusgrid').store.count() 88 var lastrow = button.up('statusgrid').store.count()
93 button.up('statusgrid').store.insert(lastrow, record);
94 button.up('statusgrid').rowEditing.startEdit(lastrow, 1);
95 },
96 89
97 90
98 /** 91 //If possible copy the previous record into the new one.
99 * When a row in a grid is selected, 92 //this assumes the store is ordered correctly, most recent status last.
100 * this function checks if the row may be edited, 93 if (lastrow > 0) {
101 * or if the row can be removed 94 //clone the old one
102 */ 95 var recentStatus = button.up('statusgrid').store.getAt(lastrow-1);
103 toggleAllowedPermissions: function(context, record, index){ 96 var record = recentStatus.copy()
97 record.set('id', null);
98 } else {
99 //create a new one
100 var record = Ext.create('Lada.model.Status', {
101 messungsId: button.up('statusgrid').recordId
102 });
103 }
104 104
105 //retrieve the readOnly parameters 105 //Set the Date
106 var statusEdit = context.view.up('window').record.get('statusEdit'); 106 record.set('datum', new Date());
107 107
108 var grid = context.view.up('grid'); 108 button.up('statusgrid').store.insert(lastrow, record);
109 109 button.up('statusgrid').getPlugin('rowedit').startEdit(lastrow, 1);
110 //retrieve the last record of the store
111 var lastRecord = context.getStore().last();
112
113 //Check if edit is allowed
114 if (lastRecord != record ||
115 statusEdit === false) {
116 grid.getPlugin('rowedit').cancelEdit();
117 }
118 } 110 }
119
120 }); 111 });

http://lada.wald.intevation.org