netzke-basepack 0.1.4.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +10 -0
- data/Manifest +13 -8
- data/README.mdown +10 -10
- data/Rakefile +1 -1
- data/css/basepack.css +4 -0
- data/generators/netzke_basepack/netzke_grid_panel_generator.rb +7 -0
- data/generators/netzke_basepack/templates/{create_netzke_grid_columns.rb → create_netzke_grid_panel_columns.rb} +4 -4
- data/javascripts/basepack.js +1 -1
- data/lib/app/models/{netzke_grid_column.rb → netzke_grid_panel_column.rb} +1 -1
- data/lib/netzke-basepack.rb +18 -6
- data/lib/netzke/accordion_panel.rb +73 -0
- data/lib/netzke/ar_ext.rb +51 -25
- data/lib/netzke/border_layout_panel.rb +119 -0
- data/lib/netzke/container.rb +5 -5
- data/lib/netzke/{grid.rb → grid_panel.rb} +30 -25
- data/lib/netzke/{grid_interface.rb → grid_panel_interface.rb} +11 -7
- data/lib/netzke/grid_panel_js_builder.rb +282 -0
- data/lib/netzke/panel.rb +4 -0
- data/lib/netzke/preference_grid.rb +4 -4
- data/lib/netzke/properties_tool.rb +51 -40
- data/lib/netzke/property_grid.rb +3 -3
- data/lib/netzke/wrapper.rb +20 -0
- data/netzke-basepack.gemspec +8 -8
- data/test/app_root/db/migrate/20081222033440_create_genres.rb +1 -0
- data/test/app_root/db/migrate/20081222035855_create_netzke_preferences.rb +1 -1
- data/test/ar_ext_test.rb +10 -2
- data/test/border_layout_panel_test.rb +28 -0
- data/test/{grid_test.rb → grid_panel_test.rb} +5 -4
- data/test/netzke_basepack_test.rb +0 -4
- metadata +26 -17
- data/generators/netzke_basepack/netzke_grid_generator.rb +0 -7
- data/lib/netzke/accordion.rb +0 -11
- data/lib/netzke/grid_js_builder.rb +0 -276
    
        data/lib/netzke/accordion.rb
    DELETED
    
    
| @@ -1,276 +0,0 @@ | |
| 1 | 
            -
            module Netzke::GridJsBuilder
         | 
| 2 | 
            -
              def js_base_class 
         | 
| 3 | 
            -
                'Ext.grid.EditorGridPanel'
         | 
| 4 | 
            -
              end
         | 
| 5 | 
            -
             | 
| 6 | 
            -
              def js_bbar
         | 
| 7 | 
            -
                <<-JS.l
         | 
| 8 | 
            -
                (config.rowsPerPage) ? new Ext.PagingToolbar({
         | 
| 9 | 
            -
                  pageSize:config.rowsPerPage, 
         | 
| 10 | 
            -
                  items:config.actions, 
         | 
| 11 | 
            -
                  store:ds, 
         | 
| 12 | 
            -
                  emptyMsg:'Empty'}) : config.actions
         | 
| 13 | 
            -
                JS
         | 
| 14 | 
            -
              end
         | 
| 15 | 
            -
             | 
| 16 | 
            -
              def js_default_config
         | 
| 17 | 
            -
                super.merge({
         | 
| 18 | 
            -
                  :store => "ds".l,
         | 
| 19 | 
            -
                  :cm => "cm".l,
         | 
| 20 | 
            -
                  :sel_model => "new Ext.grid.RowSelectionModel()".l,
         | 
| 21 | 
            -
                  :auto_scroll => true,
         | 
| 22 | 
            -
                  :click_to_edit => 2,
         | 
| 23 | 
            -
                  :track_mouse_over => true,
         | 
| 24 | 
            -
                  # :bbar => "config.actions".l,
         | 
| 25 | 
            -
                  :bbar => js_bbar,
         | 
| 26 | 
            -
                  :plugins => "plugins".l,
         | 
| 27 | 
            -
                  
         | 
| 28 | 
            -
                  #custom configs
         | 
| 29 | 
            -
                  :auto_load_data => true
         | 
| 30 | 
            -
                })
         | 
| 31 | 
            -
              end
         | 
| 32 | 
            -
              
         | 
| 33 | 
            -
              def js_before_constructor
         | 
| 34 | 
            -
                <<-JS
         | 
| 35 | 
            -
                var plugins = [];
         | 
| 36 | 
            -
              	if (!config.columns) this.feedback('No columns defined for grid '+config.id);
         | 
| 37 | 
            -
                this.recordConfig = [];
         | 
| 38 | 
            -
                Ext.each(config.columns, function(column){this.recordConfig.push({name:column.name})}, this);
         | 
| 39 | 
            -
                this.Row = Ext.data.Record.create(this.recordConfig);
         | 
| 40 | 
            -
             | 
| 41 | 
            -
                var ds = new Ext.data.Store({
         | 
| 42 | 
            -
                    proxy: this.proxy = new Ext.data.HttpProxy({url:config.interface.getData}),
         | 
| 43 | 
            -
                    reader: new Ext.data.ArrayReader({root: "data", totalProperty: "total", successProperty: "succes", id:0}, this.Row),
         | 
| 44 | 
            -
                    remoteSort: true,
         | 
| 45 | 
            -
                    listeners:{'loadexception':{
         | 
| 46 | 
            -
                      fn:this.loadExceptionHandler,
         | 
| 47 | 
            -
                      scope:this
         | 
| 48 | 
            -
                    }}
         | 
| 49 | 
            -
                });
         | 
| 50 | 
            -
                
         | 
| 51 | 
            -
                this.cmConfig = [];
         | 
| 52 | 
            -
                Ext.each(config.columns, function(c){
         | 
| 53 | 
            -
                  var editor = c.readOnly ? null : Ext.netzke.editors[c.showsAs](c, config);
         | 
| 54 | 
            -
             | 
| 55 | 
            -
                  this.cmConfig.push({
         | 
| 56 | 
            -
                    header: c.label || c.name,
         | 
| 57 | 
            -
                    dataIndex: c.name,
         | 
| 58 | 
            -
                    hidden: c.hidden,
         | 
| 59 | 
            -
                    width: c.width,
         | 
| 60 | 
            -
                    editor: editor,
         | 
| 61 | 
            -
                    sortable: true
         | 
| 62 | 
            -
                  })
         | 
| 63 | 
            -
                }, this);
         | 
| 64 | 
            -
             | 
| 65 | 
            -
                var cm = new Ext.grid.ColumnModel(this.cmConfig);
         | 
| 66 | 
            -
                
         | 
| 67 | 
            -
                this.addEvents("refresh");
         | 
| 68 | 
            -
                
         | 
| 69 | 
            -
                // Filters
         | 
| 70 | 
            -
                if (config.columnFilters) {
         | 
| 71 | 
            -
                  var filters = []
         | 
| 72 | 
            -
                  Ext.each(config.columns, function(c){
         | 
| 73 | 
            -
                    filters.push({type:Ext.netzke.filterMap[c.showsAs], dataIndex:c.name})
         | 
| 74 | 
            -
                  })
         | 
| 75 | 
            -
                	var gridFilters = new Ext.grid.GridFilters({filters:filters});
         | 
| 76 | 
            -
                  plugins.push(gridFilters);
         | 
| 77 | 
            -
                }
         | 
| 78 | 
            -
                
         | 
| 79 | 
            -
                JS
         | 
| 80 | 
            -
              end
         | 
| 81 | 
            -
              
         | 
| 82 | 
            -
              def js_config
         | 
| 83 | 
            -
                res = super
         | 
| 84 | 
            -
                # we pass column config at the time of instantiating the JS class
         | 
| 85 | 
            -
                res.merge!(:columns => get_columns || config[:columns]) # first try to get columns from DB, then from config
         | 
| 86 | 
            -
                res.merge!(:data_class_name => config[:data_class_name])
         | 
| 87 | 
            -
                res
         | 
| 88 | 
            -
              end
         | 
| 89 | 
            -
             | 
| 90 | 
            -
              def js_listeners
         | 
| 91 | 
            -
                super.merge({
         | 
| 92 | 
            -
                  :columnresize => (config[:column_resize] ? {:fn => "this.onColumnResize".l, :scope => this} : nil),
         | 
| 93 | 
            -
                  :columnmove => (config[:column_move] ? {:fn => "this.onColumnMove".l, :scope => this} : nil)
         | 
| 94 | 
            -
                })
         | 
| 95 | 
            -
              end
         | 
| 96 | 
            -
              
         | 
| 97 | 
            -
              
         | 
| 98 | 
            -
              def js_extend_properties
         | 
| 99 | 
            -
                {
         | 
| 100 | 
            -
                  :on_widget_load => <<-JS.l,
         | 
| 101 | 
            -
                    function(){
         | 
| 102 | 
            -
                      // auto-load
         | 
| 103 | 
            -
                      if (this.initialConfig.autoLoadData) {
         | 
| 104 | 
            -
                        // if we have a paging toolbar, load the first page, otherwise
         | 
| 105 | 
            -
                        if (this.getBottomToolbar().changePage) this.getBottomToolbar().changePage(0); else this.store.load();
         | 
| 106 | 
            -
                      }
         | 
| 107 | 
            -
                    }
         | 
| 108 | 
            -
                  JS
         | 
| 109 | 
            -
                  
         | 
| 110 | 
            -
                  :load_exception_handler => <<-JS.l,
         | 
| 111 | 
            -
                  function(proxy, options, response, error){
         | 
| 112 | 
            -
                    if (response.status == 200 && (responseObject = Ext.decode(response.responseText)) && responseObject.flash){
         | 
| 113 | 
            -
                      this.feedback(responseObject.flash)
         | 
| 114 | 
            -
                    } else {
         | 
| 115 | 
            -
                      if (error){
         | 
| 116 | 
            -
                        this.feedback(error.message);
         | 
| 117 | 
            -
                      } else {
         | 
| 118 | 
            -
                        this.feedback(response.statusText)
         | 
| 119 | 
            -
                      }  
         | 
| 120 | 
            -
                    }
         | 
| 121 | 
            -
                  }        
         | 
| 122 | 
            -
                  JS
         | 
| 123 | 
            -
                
         | 
| 124 | 
            -
                  :add => <<-JS.l,
         | 
| 125 | 
            -
                    function(){
         | 
| 126 | 
            -
                      var rowConfig = {};
         | 
| 127 | 
            -
                      Ext.each(this.initialConfig.columns, function(c){
         | 
| 128 | 
            -
                        rowConfig[c.name] = c.defaultValue || ''; // FIXME: if the user is happy with all the defaults, the record won't be 'dirty'
         | 
| 129 | 
            -
                      }, this);
         | 
| 130 | 
            -
                      
         | 
| 131 | 
            -
                      var r = new this.Row(rowConfig); // TODO: add default values
         | 
| 132 | 
            -
                      r.set('id', -r.id); // to distinguish new records by negative values
         | 
| 133 | 
            -
                      this.stopEditing();
         | 
| 134 | 
            -
                  		this.store.add(r);
         | 
| 135 | 
            -
                  		this.store.newRecords = this.store.newRecords || []
         | 
| 136 | 
            -
                  		this.store.newRecords.push(r);
         | 
| 137 | 
            -
                      // console.info(this.store.newRecords);
         | 
| 138 | 
            -
                      this.tryStartEditing(this.store.indexOf(r));
         | 
| 139 | 
            -
                  	}
         | 
| 140 | 
            -
                  JS
         | 
| 141 | 
            -
                
         | 
| 142 | 
            -
                  :edit => <<-JS.l,
         | 
| 143 | 
            -
                    function(){
         | 
| 144 | 
            -
                      var row = this.getSelectionModel().getSelected();
         | 
| 145 | 
            -
                      if (row){
         | 
| 146 | 
            -
                        this.tryStartEditing(this.store.indexOf(row))
         | 
| 147 | 
            -
                      }
         | 
| 148 | 
            -
                    }
         | 
| 149 | 
            -
                  JS
         | 
| 150 | 
            -
                
         | 
| 151 | 
            -
                  # try editing the first editable (not hidden, not read-only) sell
         | 
| 152 | 
            -
                  :try_start_editing => <<-JS.l,
         | 
| 153 | 
            -
                  	function(row){
         | 
| 154 | 
            -
                  	  if (row == null) return;
         | 
| 155 | 
            -
                  		var editableColumns = this.getColumnModel().getColumnsBy(function(columnConfig, index){
         | 
| 156 | 
            -
                  			return !columnConfig.hidden && !!columnConfig.editor;
         | 
| 157 | 
            -
                  		});
         | 
| 158 | 
            -
                  		// console.info(editableColumns);
         | 
| 159 | 
            -
                  		var firstEditableColumn = editableColumns[0];
         | 
| 160 | 
            -
                  		if (firstEditableColumn){
         | 
| 161 | 
            -
                  			this.startEditing(row, firstEditableColumn.id);
         | 
| 162 | 
            -
                  		}
         | 
| 163 | 
            -
                  	}
         | 
| 164 | 
            -
                  JS
         | 
| 165 | 
            -
             | 
| 166 | 
            -
                  :delete => <<-JS.l,
         | 
| 167 | 
            -
                    function() {
         | 
| 168 | 
            -
                      if (this.getSelectionModel().hasSelection()){
         | 
| 169 | 
            -
                        Ext.Msg.confirm('Confirm', 'Are you sure?', function(btn){
         | 
| 170 | 
            -
                          if (btn == 'yes') {
         | 
| 171 | 
            -
                            var records = []
         | 
| 172 | 
            -
                            this.getSelectionModel().each(function(r){
         | 
| 173 | 
            -
                      		    records.push(r.get('id'));
         | 
| 174 | 
            -
                            }, this);
         | 
| 175 | 
            -
                    		    Ext.Ajax.request({
         | 
| 176 | 
            -
                        			url: this.initialConfig.interface.deleteData,
         | 
| 177 | 
            -
                        			params: {records: Ext.encode(records)},
         | 
| 178 | 
            -
                        			success:function(r){ 
         | 
| 179 | 
            -
                        				var m = Ext.decode(r.responseText);
         | 
| 180 | 
            -
                        				this.store.reload();
         | 
| 181 | 
            -
                                // this.loadWithFeedback();
         | 
| 182 | 
            -
                        				this.feedback(m.flash);
         | 
| 183 | 
            -
                        			},
         | 
| 184 | 
            -
                        			scope:this
         | 
| 185 | 
            -
                        		});
         | 
| 186 | 
            -
                          }
         | 
| 187 | 
            -
                        }, this);
         | 
| 188 | 
            -
                      }
         | 
| 189 | 
            -
                    }
         | 
| 190 | 
            -
                  JS
         | 
| 191 | 
            -
                  :submit => <<-JS.l,
         | 
| 192 | 
            -
                    function(){
         | 
| 193 | 
            -
             | 
| 194 | 
            -
                      var newRecords = [];
         | 
| 195 | 
            -
                      if (this.store.newRecords){
         | 
| 196 | 
            -
                    		Ext.each(this.store.newRecords, function(r){
         | 
| 197 | 
            -
                    		  newRecords.push(r.getChanges())
         | 
| 198 | 
            -
                    		  r.commit() // commit the changes, so that they are not picked up by getModifiedRecords() further down
         | 
| 199 | 
            -
                    		}, this);
         | 
| 200 | 
            -
                    		delete this.store.newRecords;
         | 
| 201 | 
            -
                    	}
         | 
| 202 | 
            -
                  		
         | 
| 203 | 
            -
                    	var updatedRecords = [];
         | 
| 204 | 
            -
                  		Ext.each(this.store.getModifiedRecords(),
         | 
| 205 | 
            -
                  			function(record) {
         | 
| 206 | 
            -
                  				var completeRecordData = {};
         | 
| 207 | 
            -
                  				Ext.apply(completeRecordData, Ext.apply(record.getChanges(), {id:record.get('id')}));
         | 
| 208 | 
            -
                  				updatedRecords.push(completeRecordData);
         | 
| 209 | 
            -
                  			}, 
         | 
| 210 | 
            -
                  		this);
         | 
| 211 | 
            -
                      
         | 
| 212 | 
            -
                      if (newRecords.length > 0 || updatedRecords.length > 0) {
         | 
| 213 | 
            -
                    		Ext.Ajax.request({
         | 
| 214 | 
            -
                    			url:this.initialConfig.interface.postData,
         | 
| 215 | 
            -
                    			params: {
         | 
| 216 | 
            -
                    			  updated_records: Ext.encode(updatedRecords), 
         | 
| 217 | 
            -
                    			  created_records: Ext.encode(newRecords),
         | 
| 218 | 
            -
                    			  filters: this.store.baseParams.filters
         | 
| 219 | 
            -
                    			},
         | 
| 220 | 
            -
                    			success:function(response){
         | 
| 221 | 
            -
                    				var m = Ext.decode(response.responseText);
         | 
| 222 | 
            -
                    				if (m.success) {
         | 
| 223 | 
            -
                    					this.store.reload();
         | 
| 224 | 
            -
                              // this.loadWithFeedback();
         | 
| 225 | 
            -
                    					this.store.commitChanges();
         | 
| 226 | 
            -
                    					this.feedback(m.flash);
         | 
| 227 | 
            -
                    				} else {
         | 
| 228 | 
            -
                    					this.feedback(m.flash);
         | 
| 229 | 
            -
                    				}
         | 
| 230 | 
            -
                    			},
         | 
| 231 | 
            -
                    			failure:function(response){
         | 
| 232 | 
            -
                    				this.feedback('Bad response from server');
         | 
| 233 | 
            -
                    			},
         | 
| 234 | 
            -
                    			scope:this
         | 
| 235 | 
            -
                    		});
         | 
| 236 | 
            -
                      }
         | 
| 237 | 
            -
                      
         | 
| 238 | 
            -
                    }
         | 
| 239 | 
            -
                  JS
         | 
| 240 | 
            -
               
         | 
| 241 | 
            -
                  :refresh_click => <<-JS.l,
         | 
| 242 | 
            -
                    function() {
         | 
| 243 | 
            -
                      // console.info(this);
         | 
| 244 | 
            -
                      // if (this.fireEvent('refresh', this) !== false) this.loadWithFeedback();
         | 
| 245 | 
            -
                      if (this.fireEvent('refresh', this) !== false) this.store.reload();
         | 
| 246 | 
            -
                    }
         | 
| 247 | 
            -
                  JS
         | 
| 248 | 
            -
                  
         | 
| 249 | 
            -
                  :on_column_resize => <<-JS.l,
         | 
| 250 | 
            -
                    function(index, size){
         | 
| 251 | 
            -
                      // var column = this.getColumnModel().getDataIndex(index);
         | 
| 252 | 
            -
                      Ext.Ajax.request({
         | 
| 253 | 
            -
                        url:this.initialConfig.interface.resizeColumn,
         | 
| 254 | 
            -
                        params:{
         | 
| 255 | 
            -
                          index:index,
         | 
| 256 | 
            -
                          size:size
         | 
| 257 | 
            -
                        }
         | 
| 258 | 
            -
                      })
         | 
| 259 | 
            -
                    }
         | 
| 260 | 
            -
                  JS
         | 
| 261 | 
            -
                  
         | 
| 262 | 
            -
                  :on_column_move => <<-JS.l
         | 
| 263 | 
            -
                    function(oldIndex, newIndex){
         | 
| 264 | 
            -
                      Ext.Ajax.request({
         | 
| 265 | 
            -
                        url:this.initialConfig.interface.moveColumn,
         | 
| 266 | 
            -
                        params:{
         | 
| 267 | 
            -
                          old_index:oldIndex,
         | 
| 268 | 
            -
                          new_index:newIndex
         | 
| 269 | 
            -
                        }
         | 
| 270 | 
            -
                      })
         | 
| 271 | 
            -
                    }
         | 
| 272 | 
            -
                  JS
         | 
| 273 | 
            -
                  
         | 
| 274 | 
            -
                }
         | 
| 275 | 
            -
              end
         | 
| 276 | 
            -
            end
         |