From 5a560e93f8539811932ec42b48de0d1bda1dd3e1 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Mon, 6 Sep 2010 11:47:37 +0200 Subject: [PATCH] use sonia.rest for sonia.group --- .../src/main/webapp/resources/js/layout.js | 15 +- .../main/webapp/resources/js/sonia.group.js | 304 ++++-------------- .../main/webapp/resources/js/sonia.sample.js | 126 -------- 3 files changed, 58 insertions(+), 387 deletions(-) delete mode 100644 scm-webapp/src/main/webapp/resources/js/sonia.sample.js diff --git a/scm-webapp/src/main/webapp/resources/js/layout.js b/scm-webapp/src/main/webapp/resources/js/layout.js index 0c94e7eb67..97da8879b9 100644 --- a/scm-webapp/src/main/webapp/resources/js/layout.js +++ b/scm-webapp/src/main/webapp/resources/js/layout.js @@ -15,26 +15,13 @@ Ext.onReady(function(){ var tabPanel = new Ext.TabPanel({ region: 'center', // a center region is ALWAYS required for border layout deferredRender: false, - activeTab: 1, // first tab initially active + activeTab: 0, // first tab initially active items: [{ id: 'welcome', xtype: 'panel', title: 'Welcome', // closable: true, autoScroll: true - },{ - id: 't_sample', - xtype: 'restGrid', - title: 'Sample', - autoScroll: true, - store: groupStore, - cm: groupColModel, - idField: 'name', - searchField: 'name', - editForm: 'sampleEditForm', - restAddUrl: restUrl + 'groups.json', - restEditUrlPattern: restUrl + 'groups/{0}.json', - restRemoveUrlPattern: restUrl + 'groups/{0}.json' }] }); diff --git a/scm-webapp/src/main/webapp/resources/js/sonia.group.js b/scm-webapp/src/main/webapp/resources/js/sonia.group.js index 1392ab03ea..3633420dc0 100644 --- a/scm-webapp/src/main/webapp/resources/js/sonia.group.js +++ b/scm-webapp/src/main/webapp/resources/js/sonia.group.js @@ -5,171 +5,17 @@ Ext.ns('Sonia.group'); -var addGroupWindow = null; +Sonia.group.EditForm = new Ext.extend(Sonia.rest.EditForm, { -/** Sonia.GroupGrid **/ -function addGroup(){ - addGroupWindow = new Sonia.group.DetailWindow(); - addGroupWindow.show(); -} - -function removeGroup(){ - if (groupSelModel.hasSelection()){ - var group = groupSelModel.getSelected().data.name; - - if ( debug ){ - console.debug( 'remove group ' + group ); - } - - Ext.MessageBox.show({ - title: 'Remove Group', - msg: 'Remove Group "' + group + '"?', - buttons: Ext.MessageBox.OKCANCEL, - icon: Ext.MessageBox.QUESTION, - fn: function(result){ - if ( result == 'ok' ){ - Ext.Ajax.request({ - url: restUrl + 'groups/' + group + '.json', - method: 'DELETE', - success: function(){ - groupStore.reload(); - }, - failure: function(){ - alert('ERROR!!!') - } - }); - } - } - }); - } -} - -function editGroup(){ - if (groupSelModel.hasSelection()){ - var group = groupSelModel.getSelected().data; - - var store = new Ext.data.ArrayStore({ + initComponent: function(){ + this.store = new Ext.data.ArrayStore({ fields: [ 'name' ] }); - Ext.each(group.members, function(g,i){ - store.add( [new Ext.data.Record( {name: g} )] ); - }); - - var groupForm = new Sonia.group.AddForm({ - name: group.name, - update: true, - store: store - }); - - var win = new Sonia.group.DetailWindow({ - form: groupForm - }); - win.show(); - } -} - -var groupToolbar = new Ext.Toolbar({ - items: [ - {xtype: 'tbbutton', text: 'Add', handler: addGroup}, - {xtype: 'tbbutton', text: 'Edit', handler: editGroup}, - {xtype: 'tbbutton', text: 'Remove', handler: removeGroup}, - {xtype: 'tbseparator'}, - {xtype: 'label', text: 'Search: '}, - {xtype: 'textfield', id: 'searchfield', listeners: { - specialkey: function(field, e){ - if (e.getKey() == e.ENTER) { - var value = this.getValue(); - if ( debug ){ - console.log( 'Filter: ' + value ); - } - // TODO filter by member - groupStore.filter('name', new RegExp('.*' + value + '.*')); - } - } - }} - ] -}); - -var groupColModel = new Ext.grid.ColumnModel({ - columns: [ - {header: 'Name', sortable: true, width: 200, dataIndex: 'name'}, - {header: 'Members', sortable: true, dataIndex: 'members'} - ] -}); - -var groupSelModel = new Ext.grid.RowSelectionModel({ - singleSelect: true -}); - -var groupStore = new Sonia.rest.JsonStore({ - url: restUrl + 'groups.json', - root: 'groups', - fields: [ - 'name', 'members' - ], - sortInfo: { - field: 'name' - } -}); - -//groupStore.load(); - -Sonia.group.Grid = Ext.extend(Ext.grid.GridPanel, { - initComponent: function(){ var config = { - store: groupStore, - colModel: groupColModel, - selModel: groupSelModel, - tbar: groupToolbar, - viewConfig: { - forceFit: true - }, - loadMask: true, - listeners: { - celldblclick: editGroup - } - }; - - groupStore.load(); - - Ext.apply(this, Ext.apply(this.initialConfig, config)); - Sonia.group.Grid.superclass.initComponent.apply(this, arguments); - } -}); - -Ext.reg('groupGrid', Sonia.group.Grid); - -Sonia.group.AddForm = new Ext.extend(Ext.FormPanel, { - - containerWindow: null, - store: null, - name: '', - update: false, - - initComponent: function(){ - if ( this.store == null ){ - this.store = new Ext.data.ArrayStore({ - fields: [ 'name' ] - }); - } - - this.update = this.name != ''; - - var config = { - labelWidth: 80, - autoHeight: true, - //url: null, - frame: true, - title: 'Add Group', - defaultType:'textfield', - monitorValid: true, items:[{ fieldLabel:'Name', name:'name', - focus: ! this.update, - value: this.name, - readOnly: this.update, anchor: '100%', allowBlank: false },{ @@ -219,22 +65,32 @@ Sonia.group.AddForm = new Ext.extend(Ext.FormPanel, { scope: this, handler: this.removeSelectedMember }] - }], - - buttons:[{ - text:'Ok', - scope: this, - formBind: true, - handler: this.submit - },{ - text: 'Cancel', - scope: this, - handler: this.close }] }; Ext.apply(this, Ext.apply(this.initialConfig, config)); - Sonia.group.AddForm.superclass.initComponent.apply(this, arguments); + Sonia.group.EditForm.superclass.initComponent.apply(this, arguments); + }, + + load: function(item){ + var members = item.members; + for (var i=0; i