[Lada-commits] [PATCH] 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
Wald Commits
scm-commit at wald.intevation.org
Wed Dec 16 10:24:56 CET 2015
# HG changeset patch
# User Dustin Demuth <dustin at intevation.de>
# Date 1450255749 -3600
# Node ID c2a726887dd7bece4c592fea7e8ad0002ac1780c
# Parent b892eb346f14f2de05bb0855718fc19f5cbc604c
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.
diff -r b892eb346f14 -r c2a726887dd7 app/controller/grid/Status.js
--- a/app/controller/grid/Status.js Tue Dec 15 08:50:49 2015 +0100
+++ b/app/controller/grid/Status.js Wed Dec 16 09:49:09 2015 +0100
@@ -21,7 +21,6 @@
'statusgrid': {
edit: this.gridSave,
canceledit: this.cancelEdit,
- select: this.toggleAllowedPermissions
},
'statusgrid button[action=add]': {
click: this.add
@@ -82,39 +81,31 @@
/**
* This function adds a new row to add a Status
+ * and copies the data of the previous status into the new one
+ * if possible.
*/
add: function(button) {
- var record = Ext.create('Lada.model.Status', {
- messungsId: button.up('statusgrid').recordId
- });
+ var lastrow = button.up('statusgrid').store.count()
+
+
+ //If possible copy the previous record into the new one.
+ //this assumes the store is ordered correctly, most recent status last.
+ if (lastrow > 0) {
+ //clone the old one
+ var recentStatus = button.up('statusgrid').store.getAt(lastrow-1);
+ var record = recentStatus.copy()
+ record.set('id', null);
+ } else {
+ //create a new one
+ var record = Ext.create('Lada.model.Status', {
+ messungsId: button.up('statusgrid').recordId
+ });
+ }
+
//Set the Date
- record.data.datum = new Date();
- var lastrow = button.up('statusgrid').store.count()
+ record.set('datum', new Date());
+
button.up('statusgrid').store.insert(lastrow, record);
- button.up('statusgrid').rowEditing.startEdit(lastrow, 1);
- },
-
-
- /**
- * When a row in a grid is selected,
- * this function checks if the row may be edited,
- * or if the row can be removed
- */
- toggleAllowedPermissions: function(context, record, index){
-
- //retrieve the readOnly parameters
- var statusEdit = context.view.up('window').record.get('statusEdit');
-
- var grid = context.view.up('grid');
-
- //retrieve the last record of the store
- var lastRecord = context.getStore().last();
-
- //Check if edit is allowed
- if (lastRecord != record ||
- statusEdit === false) {
- grid.getPlugin('rowedit').cancelEdit();
- }
+ button.up('statusgrid').getPlugin('rowedit').startEdit(lastrow, 1);
}
-
});
diff -r b892eb346f14 -r c2a726887dd7 app/view/grid/Status.js
--- a/app/view/grid/Status.js Tue Dec 15 08:50:49 2015 +0100
+++ b/app/view/grid/Status.js Wed Dec 16 09:49:09 2015 +0100
@@ -37,8 +37,22 @@
this.rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
clicksToMoveEditor: 1,
autoCancel: false,
- disabled: true,
- pluginId: 'rowedit'
+ disabled: true, //has no effect... but why?
+ pluginId: 'rowedit',
+ listeners: {
+ beforeedit: function(editor, context, eOpts) {
+ if (context.record.get('id') ||
+ ! context.grid.up('window').record.get('statusEdit')) {
+ //Check if edit is allowed, this is true, when the selected
+ // Record has an id (=is not new)
+ // or is not allowed to add records.
+
+ return false;
+ }
+
+
+ }
+ }
});
this.plugins = [this.rowEditing];
@@ -147,11 +161,16 @@
this.store.removeAll();
}
else {
- this.store = Ext.create('Lada.store.Status');
+ this.store = Ext.create('Lada.store.Status',{
+ sorters: [{
+ property: 'datum',
+ direction: 'ASC'
+ }]
+ });
}
this.store.load({
params: {
- messungsId: this.recordId
+ messungsId: this.recordId,
}
});
},
More information about the Lada-commits
mailing list