commit 07411d16d6f5af8073d1c6c8580af7dcf6a12ed2
parent 283c3230523bae95453d0aaf1edb5d0d7103555f
Author: Felicitus <felicitus@felicitus.org>
Date: Thu, 5 Jul 2012 00:50:51 +0200
Added support for creating identical copies of parts
Diffstat:
3 files changed, 74 insertions(+), 3 deletions(-)
diff --git a/src/frontend/js/Components/Part/Editor/PartEditor.js b/src/frontend/js/Components/Part/Editor/PartEditor.js
@@ -385,11 +385,34 @@ Ext.define('PartKeepr.PartEditor', {
_onItemSaved: function () {
this.fireEvent("partSaved", this.record);
- if (this.keepOpenCheckbox.getValue() !== true) {
+ if (this.keepOpenCheckbox.getValue() !== true && this.createCopyCheckbox.getValue() !== true) {
this.fireEvent("editorClose", this);
} else {
- var newItem = Ext.create("PartKeepr.Part", this.partDefaults);
- this.editItem(newItem);
+ var newItem;
+ if (this.partMode == "create") {
+ if (this.copyPartDataCheckbox.getValue() === true) {
+ data = this.record.getData(true);
+ data.id = null;
+ newItem = Ext.create("PartKeepr.Part");
+ newItem.setDataWithAssociations(data);
+
+ this.editItem(newItem);
+ } else {
+ newItem = Ext.create("PartKeepr.Part", this.partDefaults);
+ this.editItem(newItem);
+ }
+ } else {
+ var data = this.record.getData(true);
+ data.id = null;
+ newItem = Ext.create("PartKeepr.Part");
+ newItem.setDataWithAssociations(data);
+
+ this.editItem(newItem);
+ }
+
+
+
+
}
},
bindChildStores: function () {
diff --git a/src/frontend/js/Components/Part/Editor/PartEditorWindow.js b/src/frontend/js/Components/Part/Editor/PartEditorWindow.js
@@ -79,11 +79,27 @@ Ext.define('PartKeepr.PartEditorWindow', {
boxLabel: i18n("Create blank item after save")
});
+ this.createCopyCheckbox = Ext.create("Ext.form.field.Checkbox", {
+ boxLabel: i18n("Create Copy after save")
+ });
+
+ this.copyPartDataCheckbox = Ext.create("Ext.form.field.Checkbox", {
+ boxLabel: i18n("Takeover all data"),
+ disabled: true
+ });
+
if (this.partMode == "create") {
this.bottomToolbar.add(this.keepOpenCheckbox);
+ this.bottomToolbar.add(this.copyPartDataCheckbox);
+ } else {
+ this.bottomToolbar.add(this.createCopyCheckbox);
}
+ this.keepOpenCheckbox.on("change", this.onKeepOpenCheckboxClick, this);
+
this.editor.keepOpenCheckbox = this.keepOpenCheckbox;
+ this.editor.copyPartDataCheckbox = this.copyPartDataCheckbox;
+ this.editor.createCopyCheckbox = this.createCopyCheckbox;
this.callParent();
},
@@ -91,6 +107,17 @@ Ext.define('PartKeepr.PartEditorWindow', {
this.editor.onCancelEdit();
},
/**
+ * Listens to the keepOpenCheckbox clicks and enables/disables the copyPartDataCheckbox
+ * @param value
+ */
+ onKeepOpenCheckboxClick: function (field, value) {
+ if (value) {
+ this.copyPartDataCheckbox.enable();
+ } else {
+ this.copyPartDataCheckbox.disable();
+ }
+ },
+ /**
* Called when the save button was clicked
*/
onItemSave: function () {
diff --git a/src/frontend/js/ExtJS/Enhancements/Ext.data.Model-setDataWithAssociations.js b/src/frontend/js/ExtJS/Enhancements/Ext.data.Model-setDataWithAssociations.js
@@ -0,0 +1,20 @@
+Ext.override(Ext.data.Model, {
+ /**
+ * Sets the data including associations.
+ *
+ * @param data A plain object which represents the data. This can come from model.getData(true).
+ */
+ setDataWithAssociations: function (data) {
+ for (var i in data) {
+ if (this.fields.containsKey(i)) {
+ this.set(i, data[i]);
+ }
+
+ if (this.associations.containsKey(i)) {
+ var store = this[i]();
+ store.add(data[i]);
+ }
+ }
+
+ }
+});+
\ No newline at end of file