1 // we use the metadata loaded into the stash to create window tabs 2 // each tab is one table 3 // all tabs are in the same "form" wrt ajax submission 4 5 // most of the messing about is to get the right form field types 6 // also readonly, validation 7 8 [% SET tab_order = [ '' ] %] 9 [% FOREACH col IN cpac.tc.cols %] 10 [% NEXT UNLESS cpac.tm.f.$col.extra('rel_type') == 'belongs_to' %] 11 [% tab_order.push( col ) %] 12 [% END %] 13 14 var tabs = [ 15 [% FOREACH orig_col IN tab_order %] 16 [% SET tbl = cpac.tm.f.$orig_col.extra('ref_table') || cpac_table %] 17 [% SET conf = cpac.c.$cpac_db.t.$tbl %] 18 [% SET meta = cpac.m.t.$tbl %] 19 20 [% NEXT IF conf.create_allowed == 'no' OR conf.update_allowed == 'no' %] 21 [% ',' IF orig_col != '' %]{ 22 [% IF orig_col == '' %] 23 title: '[% conf.display_name %]' 24 [% ELSE %] 25 title: 'New [% cpac.tm.f.$orig_col.extra('display_name') %]' 26 ,xtype: 'fieldset' 27 ,checkboxToggle: true 28 ,checkboxName: 'checkbox.[% orig_col %]' 29 ,collapsed: true 30 [% END %] 31 32 ,items: [ 33 [% SET count = 1 %] 34 [% FOREACH field IN conf.cols %] 35 [% NEXT IF meta.f.$field.extra('is_reverse') OR meta.f.$field.extra('masked_by') %] 36 [% NEXT IF orig_col != '' AND meta.f.$field.extra('is_proxy') %] 37 [% ',' IF count > 1 %]{ 38 [% IF orig_col == '' %] 39 [% IF count == 1 %] 40 name: 'cpac__id' 41 ,id: 'cpac__id' 42 ,xtype: 'hidden' 43 },{ 44 [% END %] 45 name: '[% field | replace('\'', '\\\'') %]' 46 ,id: '[% field | replace('\'', '\\\'') %]' 47 [% ELSE %] 48 name: '[% orig_col %].[% field | replace('\'', '\\\'') %]' 49 ,id: '[% orig_col %].[% field | replace('\'', '\\\'') %]' 50 [% END %] 51 52 [%= SET count = count + 1 %] 53 [% IF meta.f.$field.is_auto_increment %] 54 ,xtype: 'hidden' 55 }[% NEXT %] 56 [% END -%] 57 58 ,fieldLabel: '[% conf.headings.$field %]' 59 ,anchor: '-20' 60 ,autoHeight: true 61 62 [%= IF meta.f.$field.default_value.defined %] 63 ,value: '[% meta.f.$field.default_value | replace('\'', '\\\'') %]' 64 [% END %] 65 66 [%= IF NOT meta.f.$field.is_nullable 67 AND (NOT meta.f.$field.default_value.defined OR meta.f.$field.default_value) %] 68 ,allowBlank: false 69 [% END %] 70 71 [%= IF meta.f.$field.is_foreign_key %] 72 ,xtype: 'combo' 73 ,displayField: 'stringified' 74 ,valueField: 'dbid' 75 [% IF orig_col == '' %] 76 ,hiddenName: 'combobox.[% field | replace('\'', '\\\'') %]' 77 [% ELSE %] 78 ,hiddenName: 'combobox.[% orig_col %].[% field | replace('\'', '\\\'') %]' 79 [% END %] 80 ,loadingText: 'Searching...' 81 ,forceSelection: true 82 ,selectOnFocus: true 83 ,typeAhead: false 84 ,pageSize: 5 85 ,triggerAction: 'all' 86 ,store: new Ext.data.JsonStore ({ 87 url: '[% c.uri_for( 88 c.controller('AutoCRUD::DisplayEngine::ExtJS2').action_for('list_stringified'), 89 [cpac.g.site,cpac_db,tbl] 90 ) %]' 91 ,root: 'rows' 92 ,totalProperty: 'total' 93 ,fields: [ 'dbid', 'stringified' ] 94 ,listeners: { 95 beforeload: function(store, options) { 96 var start = options.params.start; 97 var limit = options.params.limit; 98 options.params.page = Math.floor(start / limit) + 1; 99 options.params.fkname = '[% field %]'; 100 return true; 101 } 102 } 103 }) 104 // allow clearing of value 105 ,listeners: { 106 blur : function() { 107 if (this.allowBlank && this.getRawValue() === '') { 108 this.clearValue(); 109 } 110 } 111 } 112 [% ELSE %] 113 [% SET localxtype = meta.f.$field.extra('extjs_xtype') OR "textarea" %] 114 ,xtype: '[% localxtype %]' 115 116 [%= SWITCH localxtype %] 117 [% CASE 'timefield' %] 118 ,format: 'H:i:s' 119 [% CASE 'datefield' %] 120 ,format: 'Y-m-d' 121 [% CASE 'xdatetime' %] 122 ,otherToNow: false 123 ,dateFormat: 'Y-m-d' 124 ,timeFormat: 'H:i:s' 125 [% CASE 'textarea' %] 126 ,grow: true 127 ,growMin: 0 128 ,growMax: 200 129 ,autoHeight: true 130 [% END %] 131 [% END %] 132 } 133 [% END %] 134 ] 135 } 136 [% END %] 137 ]; 138