Ejemplo n.º 1
0
 private void endNew(Model newModel) {
   if (Session.current.isEditingSub()) {
     // Create new record
     String linkToParent = Session.current.linkToParent;
     String linkToSelf = Session.current.linkToSelf;
     Session.current.finishEditing();
     Session.current.editNewOne2Many(newModel.getClassName(), linkToParent, linkToSelf);
   } else {
     // Just create a new record
     Session.current.finishEditing();
     Session.current.editNewModel(newModel.getClassName());
   }
   TreeView.setDirty();
   this.refreshDisplay();
 }
Ejemplo n.º 2
0
 /** Set session to edit a many2many subrecord. */
 public void editMany2Many(Model data, String parentField) {
   this.tempModel = new Model(data.getClassName());
   this.tempModel.set("id", data.get("id"));
   this.editedModel = data;
   this.linkToParent = parentField;
   this.linkToSelf = null;
   this.pushStack();
 }
Ejemplo n.º 3
0
 /** Set session to edit a record. */
 public void editModel(Model data) {
   this.editedModel = data;
   this.tempModel = new Model(data.getClassName());
   this.tempModel.set("id", data.get("id"));
   this.linkToParent = null;
   this.linkToSelf = null;
   this.pushStack();
 }
Ejemplo n.º 4
0
 /** Add a create call to the queue, update db and start a new record */
 private void queueCreate() {
   Model newModel = Session.current.tempModel;
   Model queuedModel = new Model(newModel.getClassName());
   queuedModel.merge(newModel);
   // Make it pending (also sets temp id for create)
   DelayedRequester.current.queueCreate(queuedModel, this.view, this);
   this.postCreate(queuedModel);
 }
Ejemplo n.º 5
0
 /** Add a update call to the queue, update db and return */
 private void queueUpdate() {
   Model newModel = Session.current.tempModel;
   Model oldModel = Session.current.editedModel;
   Model queuedModel = new Model(newModel.getClassName());
   queuedModel.merge(oldModel);
   queuedModel.merge(newModel);
   // Make it pending
   DelayedRequester.current.queueUpdate(queuedModel, this.view, this);
   this.postUpdate(queuedModel);
 }
Ejemplo n.º 6
0
 private void postCreate(Model newModel) {
   // Save locally
   DataCache db = new DataCache(this);
   db.addOne(newModel.getClassName());
   db.storeData(newModel.getClassName(), newModel);
   // Update parent if necessary
   if (Session.current.isEditingSub()) {
     // Add the id to parent
     int id = (Integer) newModel.get("id");
     Session.current.addToParent(id);
   }
   if (!Session.current.isEditingTop() && Session.current.linkToParent == null) {
     // Quit when creating a new many2many
     this.endQuit();
   } else {
     if (this.dirtyQuit) {
       this.endQuit();
     } else {
       this.endNew(newModel);
     }
   }
 }
Ejemplo n.º 7
0
 /**
  * Set session to edit a one2many subrecord. ParentField is the name of the field that links to
  * new model.
  */
 public void editOne2Many(Model data, String parentField, String childField) {
   this.tempModel = new Model(data.getClassName());
   if (data.hasAttribute("id")) {
     // When editing a new one2many record, the record has no id
     this.tempModel.set("id", data.get("id"));
   }
   if (this.editedModel != null && this.editedModel.hasAttribute("id")) {
     this.tempModel.set(childField, (Integer) this.editedModel.get("id"));
   }
   this.editedModel = data;
   this.linkToParent = parentField;
   this.linkToSelf = childField;
   this.pushStack();
 }
Ejemplo n.º 8
0
 private void postUpdate(Model updated) {
   // Save locally and continue
   DataCache db = new DataCache(this);
   db.storeData(updated.getClassName(), updated);
   this.endQuit();
 }