Commits

Sebastian Sdorra committed 7a059ad

implement showEditWindow in sonia.rest.js

  • Participants
  • Parent commits 07bf093

Comments (0)

Files changed (2)

File scm-webapp/src/main/webapp/resources/js/sonia.rest.js

 Sonia.rest.EditForm = Ext.extend(Ext.form.FormPanel, {
 
   title: 'Edit REST',
+  data: null,
 
   initComponent: function(){
 
 
     Ext.apply(this, Ext.apply(this.initialConfig, config));
     Sonia.rest.EditForm.superclass.initComponent.apply(this, arguments);
+
+    if ( this.data != null ){
+      this.load(this.data);
+    }
   },
 
   load: function(item){
 
               var store = this.store;
 
+              if ( debug ){
+                console.debug( 'add item ' + item[this.idField] );
+              }
+
               Ext.Ajax.request({
                 url: this.restAddUrl,
                 jsonData: item,
 
   showEditWindow: function(){
     if ( this.selModel.hasSelection() ){
-      console.debug( 'showEditWindow' );
+
+      var data = this.selModel.getSelected().data;
+
+      var editWindow = new Sonia.rest.DetailWindow({
+        items: [{
+          id: 'editForm',
+          xtype: this.editForm,
+          data: data,
+          listeners: {
+            submit: {
+              fn: function(item){
+
+                var store = this.store;
+                var id = item[this.idField];
+                var url = String.format(this.restEditUrlPattern, id);
+
+                if ( debug ){
+                  console.debug( 'update item ' + id );
+                }
+
+                Ext.Ajax.request({
+                  url: url,
+                  jsonData: item,
+                  method: 'PUT',
+                  success: function(){
+                    store.reload();
+                    editWindow.close();
+                  },
+                  failure: function(){
+                    alert( 'failure' );
+                  }
+                });
+
+              },
+              scope: this
+            },
+            cancel: function(){
+              editWindow.close();
+            }
+          }
+        }]
+      });
+
+      editWindow.show();
     }
   },
 

File scm-webapp/src/main/webapp/resources/js/sonia.sample.js

     Sonia.sample.EditForm.superclass.initComponent.apply(this, arguments);
   },
 
+  load: function(item){
+    var members = item.members;
+    for (var i=0; i<members.length; i++){
+      this.store.add( [ new Ext.data.Record( {name: members[i]}) ] );
+    }
+    this.getForm().loadRecord({success: true, data: item});
+  },
+
   getItem: function(form){
 
     var memberArray = [];