5 * [Roo.grid.grid] << convert a cfg into a table.
6 * [Roo.grid.grid-edit] << create a config from a tree.
9 * My initial idea was to parse the existing nodes, to generate the cfg.
10 * -- this is far too complicated..
11 * -- let's go back to the idea of storing the config on the relivant nodes.
12 * -- The downside is that if you modify the children, then the wizard will
13 * not know about those columns. etc..
20 Pman.Builder.Wizard = {
27 'time' : 'string', //bogus
34 'timestamp' : 'date', // for postgres... it's a date!??
43 'longtext' : 'string',
44 'tinytext' : 'string',
45 'mediumtext' : 'string',
52 * @param {Object} cfg the configuration
53 * @param {Object} old the previous def...
55 * - cols_ex : [ name, name]
63 - gen config - prior to editing
67 'Roo.GridPanel' : function(cfg, old)
73 var gi = _t['Roo.grid.Grid'](cfg);
79 '.builderCfg' : Roo.encode(cfg),
87 "|activate": "function() {\n _this.panel = this;\n if (_this.grid) {\n _this.grid.footer.onClick('first');\n }\n}"
94 'Roo.grid.Grid' : function(cfg, old)
103 Roo.each(cfg.cols, function(cc) {
104 colmodel.push( _t['Roo.grid.ColumnModel'](cc) );
107 var dataSource = _t['Roo.data.Store'](cfg);
108 dataSource['*prop'] = 'dataSource';
112 '.builderCfg' : Roo.encode(cfg),
113 "autoExpandColumn": cfg.cols_ex[0],
116 "|render": "function() \n" +
118 " _this.grid = this; \n" +
119 " //_this.dialog = Pman.Dialog.FILL_IN\n" +
120 " if (_this.panel.active) {\n" +
121 " this.footer.onClick('first');\n" +
124 "|rowdblclick": "function (_self, rowIndex, e)\n" +
126 " if (!_this.dialog) return;\n" +
127 " _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {\n" +
128 " _this.grid.footer.onClick('first');\n" +
138 "xtype": "PagingToolbar",
141 "displayMsg": "Displaying " + cfg.table + "{0} - {1} of {2}",
142 "emptyMsg": "No " + cfg.table + " found",
153 "cls": "x-btn-text-icon",
154 "|icon": "Roo.rootURL + 'images/default/dd/drop-add.gif'",
156 "|click": "function()\n"+
158 " if (!_this.dialog) return;\n" +
159 " _this.dialog.show( { id : 0 } , function() {\n"+
160 " _this.grid.footer.onClick('first');\n"+
164 "|xns": "Roo.Toolbar"
169 "cls": "x-btn-text-icon",
170 "|icon": "Roo.rootURL + 'images/default/tree/leaf.gif'",
172 "|click": "function()\n"+
174 " var s = _this.grid.getSelectionModel().getSelections();\n"+
175 " if (!s.length || (s.length > 1)) {\n"+
176 " Roo.MessageBox.alert(\"Error\", s.length ? \"Select only one Row\" : \"Select a Row\");\n"+
179 " if (!_this.dialog) return;\n" +
180 " _this.dialog.show(s[0].data, function() {\n"+
181 " _this.grid.footer.onClick('first');\n"+
187 "|xns": "Roo.Toolbar"
191 "cls": "x-btn-text-icon",
192 "|icon": "rootURL + '/Pman/templates/images/trash.gif'",
195 "|click": "function()\n"+
197 " Pman.genericDelete(_this, '" + cfg.table + "'); \n"+
201 "|xns": "Roo.Toolbar"
210 'Roo.data.Store' : function(cfg, old)
217 var jreader = _t['Roo.data.JsonReader'](cfg);
222 '.builderCfg' : Roo.encode(cfg),
224 '|sortInfo' : "{ field : '" + cfg.cols_ex[0] + "', direction: 'ASC' }",
228 "xtype": "HttpProxy",
230 "|url": "baseURL + '/Roo/" +cfg.table + ".php'",
240 'Roo.data.JsonReader' : function(cfg, old)
242 // simple version to start with..
252 Roo.each(cfg.cols, function(cc) {
253 var ty = typeof(_t.typemap[cc.ctype]) == 'undefined' ? 'string' : _t.typemap[cc.ctype];
254 if (cc.ctype == 'string' ) {
255 fields.push(cc.column);
258 fields.push({ name : cc.column, type : _t.typemap[cc.ctype]} );
265 xtype : "JsonReader",
266 totalProperty : "total",
268 '.builderCfg' : Roo.encode(cfg),
270 id : 'id', // maybe no..
272 '|fields' : JSON.stringify(fields, null,4).replace(/"/g,"'")
277 'Roo.grid.ColumnModel' : function(rcfg, old)
279 // simple version to start with..
280 var ty = typeof(this.typemap[rcfg.ctype]) == 'undefined' ? 'string' : this.typemap[rcfg.ctype];
282 // some special kludges..
283 // remove table prefix..
285 var desc = rcfg.columnshort;
286 if (desc.substring(0, rcfg.table.length+1) == rcfg.table+'_') {
287 desc = desc.substring(rcfg.table.length+1);
289 desc = desc.replace(/_id$/, '');
294 if (rcfg.title && rcfg.title.length) {
300 "xtype": "ColumnModel",
301 '.builderCfg' : Roo.encode(rcfg),
303 "width": ty == 'string' ? 200 : 75,
304 "dataIndex": rcfg.column,
305 "|renderer": ty != 'date' ?
306 "function(v) { return String.format('{0}', v); }" :
307 "function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); }" , // special for date
309 "*prop": "colModel[]"
315 'Roo.LayoutDialog' : function(rcfg, old)
317 // simple version to start with..
320 var frmCfg = _t['Roo.form.Form'](rcfg, old);
322 // loop through the cols..
323 // we need a 'display column' for each of these.
324 // we could also have a 'renderer'...
329 var formHeight = (frmCfg.items.length * 25) + 100; // work out from number of form ites..
332 xtype : 'LayoutDialog',
334 '.builderCfg' : Roo.encode(rcfg),
341 title: "Edit / Create " + rcfg.table,
348 "xtype": "LayoutRegion",
353 "xtype": "ContentPanel",
361 "click": "function (_self, e)\n{\n _this.dialog.hide();\n}"
363 "*prop": "buttons[]",
370 "click": "function (_self, e)\n{\n // do some checks?\n \n \n _this.dialog.el.mask(\"Saving\");\n _this.form.doAction(\"submit\");\n\n}"
372 "*prop": "buttons[]",
380 'Roo.form.Form' : function(rcfg, old)
382 // simple version to start with..
385 var formElements = [];
387 var fcombo = function(cn) {
390 Roo.each(rcfg.cols_ex, function(n) {
393 ['match' , n , 'to', cn, n.substring(0,cn.length) ].join(' ')
395 if (n.substring(0,cn.length) == cn) {
401 Roo.log("RETURN: " + cret);
405 Roo.each(rcfg.cols, function(cc) {
407 var ty = typeof(_t.typemap[cc.ctype]) == 'undefined' ? 'string' : _t.typemap[cc.ctype];
409 if (ty == 'string' ) {
410 formElements.push( _t['Roo.form.TextField'](cc, {}));
414 formElements.push( _t['Roo.form.DateField'](cc, {}));
417 if (ty == 'float' ) {
418 formElements.push( _t['Roo.form.NumberField'](cc, {}));
422 cc.display = fcombo(cc.column);
423 if (cc.deps && cc.display.length) {
424 formElements.push( _t['Roo.form.ComboBox'](cc, {}));
427 formElements.push( _t['Roo.form.NumberField'](cc, {}));
440 "|actioncomplete" : "function(_self,action)\n"+
442 " if (action.type == 'setdata') {\n"+
443 " //this.load({ method: 'GET', params: { '_id' : _this.data.id }});\n"+
446 " if (action.type == 'load') {\n"+
449 " if (action.type =='submit') {\n"+
451 " _this.dialog.hide();\n"+
453 " if (_this.callback) {\n"+
454 " _this.callback.call(_this, _this.form.getValues());\n"+
456 " _this.form.reset();\n"+
461 "|rendered" : "function (form)\n"+
463 " _this.form= form;\n"+
467 style : "margin:10px;",
468 "|url" : "baseURL + '/Roo/" + rcfg.table + ".php'",
473 'Roo.form.TextField' : function(rcfg, old)
475 var desc = rcfg.columnshort;
476 if (desc.substring(0, rcfg.table.length+1) == rcfg.table+'_') {
477 desc = desc.substring(rcfg.table.length+1);
479 desc = desc.replace(/_id$/, '');
484 if (rcfg.title && rcfg.title.length) {
499 'Roo.form.NumberField' : function(rcfg, old)
501 var desc = rcfg.columnshort;
502 if (desc.substring(0, rcfg.table.length+1) == rcfg.table+'_') {
503 desc = desc.substring(rcfg.table.length+1);
505 desc = desc.replace(/_id$/, '');
510 if (rcfg.title && rcfg.title.length) {
514 xtype : 'NumberField',
524 'Roo.form.DateField' : function(rcfg, old)
526 var desc = rcfg.columnshort;
527 if (desc.substring(0, rcfg.table.length+1) == rcfg.table+'_') {
528 desc = desc.substring(rcfg.table.length+1);
530 desc = desc.replace(/_id$/, '');
535 if (rcfg.title && rcfg.title.length) {
539 xtype : 'NumberField',
549 'Roo.form.ComboBox' : function(in_rcfg, old)
558 * column 'it maps to'
565 var table , desc, display, idcol, hiddenName, name;
567 // rcfg can be one of two things: (from a form)
570 display = rcfg.cols_ex[0];
575 var ix = rcfg.cols[0].columnshort == display ? 0 : 1;
577 idcol = rcfg.cols[ ix ? 0 : 1 ].columnshort;
579 desc = rcfg.cols[ix].title;
581 desc = rcfg.cols[ix].column;
582 if (desc.substring(0, table.length+1) == table+'_') {
583 desc = desc.substring(table.length+1);
585 desc = desc.replace(/_id$/, '');
587 desc = rcfg.cols[0].column;
591 { name : idcol, type : 'int' },
601 desc = rcfg.columnshort;
602 if (desc.substring(0, rcfg.table.length+1) == rcfg.table+'_') {
603 desc = desc.substring(rcfg.table.length+1);
605 desc = desc.replace(/_id$/, '');
610 if (rcfg.title && rcfg.title.length) {
613 // set the display column (from the remote table)
614 display = rcfg.display;
615 Roo.each(rcfg.deps, function(dn) {
616 if (dn.column == rcfg.display) {
617 display = dn.columnshort;
622 table = rcfg.deps[0].table;
623 idcol = rcfg.maps_to;
624 hiddenName = rcfg.column;
625 name = rcfg.column + '_' + display;
628 // a reader...( basic as we do meta queries to get the real one..)
630 { name : idcol , type : 'int' },
641 emptyText : 'Select ' + table,
642 forceSelection : true,
644 loadingText: 'Searching...',
647 qtip: 'Select ' + table,
649 triggerAction : 'all',
654 tpl : '<div class="x-grid-cell-text x-btn button"><b>{'+ display + '}</b> </div>',
655 queryParam : 'query['+display+']',
660 displayField : display,
663 hiddenName : hiddenName,
670 '|sortInfo' : '{ direction : \'ASC\', field: \'' + display +'\' }',
676 '|beforeload' : 'function (_self, o)' +
678 " o.params = o.params || {};\n" +
679 " // set more here\n" +
685 'xtype' : 'HttpProxy',
688 '|url' : "baseURL + '/Roo/" + table + ".php'"
693 'xtype' : 'JsonReader',
697 'totalProperty' : 'total',
698 '|fields' : JSON.stringify(combofields)