check file exists
[Pman.Core] / Pman.Std.js
1 //<script type="text/javascript">
2
3 /**
4
5 * All Our standard form fields
6
7 * should move this really..
8
9 */
10
11 Pman.Std = {
12     project_id : function (cfg) {
13         cfg = cfg || {};
14         cfg.storeListeners = cfg.storeListeners || {};
15         return  Roo.apply({
16                 
17             width: 200,
18             fieldLabel: "Project",
19             name : 'project_id_code',
20             hiddenName:  'project_id',
21             
22             allowBlank : false,
23             selectOnFocus:true,
24             qtip : "Select Project",
25             
26             
27             
28             xtype: 'ComboBox',
29             
30             store: {
31                 xtype : 'Store',
32                   // load using HTTP
33                 proxy: {
34                     xtype : 'HttpProxy',
35                     url: baseURL + '/Roo/Projects.html',
36                     method: 'GET'
37                 },
38                 reader: new Roo.data.JsonReader({}, []), //Pman.Readers.Projects,
39                 listeners : Roo.apply(
40                     {
41                         loadexception : Pman.loadException
42                     }, 
43                     cfg.storeListeners
44                 ),
45                 remoteSort : true,
46                 sortInfo: {
47                     field: 'code', direction: 'ASC'
48                 }
49             },
50             displayField:'code',
51             valueField : 'id',
52             
53             typeAhead: true,
54             forceSelection: true,
55             //mode: 'local',
56             triggerAction: 'all',
57             tpl: new Ext.Template(
58                 '<div class="x-grid-cell-text x-btn button">',
59                     '<b>{code}</b> {name}',
60                 '</div>'
61             ),
62             queryParam: 'query[project_search]',
63             loadingText: "Searching...",
64             listWidth: 400,
65            
66             minChars: 2,
67             pageSize:20 
68              
69         }, cfg);
70    },
71    
72     
73    company_id : function(cfg) { // really picks names...
74         cfg = cfg || {};
75         cfg.storeListeners = cfg.storeListeners || {};
76         // we may want to set up cfg listners default here???
77         cfg.listeners = cfg.listeners || {};
78            
79         return Roo.apply({
80                 // things we might want to change...
81                 
82                 name : 'addressto_name',
83                 displayField:'name',
84                 
85                 fieldLabel : "Sent To",
86                  qtip : "Enter Sent To",
87                 width: 290,
88                 
89                 
90                 value : '',
91                 xtype: 'ComboBoxAdder',
92                 selectOnFocus:true,
93                 allowBlank : false,
94                 
95                
96                 store: {
97                       // load using HTTP
98                     xtype: 'Store',
99                     proxy: {
100                         xtype : 'HttpProxy',
101                         url: baseURL + '/Roo/core_company',
102                         method: 'GET'
103                     },
104                     reader: Pman.Readers.Companies,
105                     
106                     listeners : Roo.apply(
107                         {
108                             loadexception : Pman.loadException
109                         }, 
110                         cfg.storeListeners
111                     ),
112                     remoteSort : true,
113                     sortInfo: {
114                         field: 'name', direction: 'ASC'
115                     }
116                     
117                 },
118               
119                 typeAhead: true,
120                 forceSelection: true,
121                 //mode: 'local',
122                 triggerAction: 'all',
123                 tpl: new Ext.Template(
124                     '<div class="x-grid-cell-text x-btn button">',
125                         '<b>{name}</b> {address}',
126                     '</div>'
127                 ),
128                 queryParam: 'query[name]',
129                 loadingText: "Searching...",
130                 listWidth: 400,
131                
132                 minChars: 2,
133                 pageSize:20 
134                 
135             }, cfg);
136     },
137     
138     doctype_name: function(cfg) {
139         cfg = cfg || {};
140         return Roo.apply({
141                 // things that might need chnaging
142                 name : 'doctype_name',
143                 width : 290,
144                 fieldLabel : "Type",
145                 allowBlank : false,
146                 
147                 // less likely
148                 qtip : "Select Document Type",
149                 
150                 value : '',
151                 // very unlinkly
152                 xtype : 'ComboBox',   
153                 store: {
154                     // load using HTTP
155                     xtype: 'Store',
156                     proxy: {
157                         xtype: 'HttpProxy',
158                         url: baseURL + '/Roo/Document_Types.html',
159                         method: 'GET'
160                     },
161                     
162                     reader: Pman.Readers.Document_Types,
163                     listeners : {
164                         beforeload: function(t, o) {
165                             //console.log(o.params);
166                             o.params.limit = 9999;
167                         },
168                         loadexception : Pman.loadException
169                 
170                     },
171                     remoteSort: true,
172                     sortInfo: {
173                         field: 'name', direction: 'ASC'
174                     }
175                 },
176                 displayField:'name',
177                 
178                 typeAhead: false,
179                 editable: false,
180                 //mode: 'local',
181                 triggerAction: 'all',
182                 //emptyText:'Select a state...',
183                 selectOnFocus:true 
184             }, cfg);
185     },
186     
187     
188     address_list_adder : function(cfg) {
189         cfg = cfg || {};
190         cfg.storeListeners = cfg.storeListeners || {};
191         return Roo.apply({
192                 
193                 name : 'send_to',
194                 fieldLabel : "To",
195                 idField : 'email',
196                 
197                  renderer : function(d) {
198                     return String.format('{0}', 
199                         d.name.length ? d.name : d.email
200                     );
201                 },
202                 
203                 
204                 xtype: 'ComboBoxLister',
205                 displayField:'name',
206                 value : '',
207                
208                 qtip : "Select an address to add.",
209                 selectOnFocus:true,
210                 allowBlank : true,
211                 width: 150,
212                 
213                 
214                 store: {
215                     xtype : 'Store',
216                       // load using HTTP
217                     proxy: {
218                         xtype : 'HttpProxy',
219                         url: baseURL + '/Roo/core_person',
220                         method: 'GET'
221                     },
222                     reader: Pman.Readers.Companies,
223                     listeners : cfg.storeListeners, 
224                     remoteSort : true,
225                     sortInfo: {
226                         field: 'name', direction: 'ASC'
227                     }
228                 },
229                
230                 
231                 typeAhead: true,
232                 forceSelection: true,
233                 //mode: 'local',
234                 triggerAction: 'all',
235                 tpl: new Ext.Template(
236                     '<div class="x-grid-cell-text x-btn button">',
237                         '<b>{name}</b> {email}',
238                     '</div>'
239                 ),
240                 queryParam: 'query[name]',
241                 loadingText: "Searching...",
242                 listWidth: 400,
243                
244                 minChars: 2,
245                 pageSize:20,
246                 setList : function(ar) {
247                     var _this = this;
248                     Roo.each(ar, function(a) {
249                         _this.addItem(a);
250                     });
251                 },
252                 toList : function() {
253                     var ret = [];
254                     this.items.each(function(a) {
255                         ret.push(a.data);
256                     });
257                     return ret;
258                 }
259                 
260                  
261             }, cfg);
262     },
263     
264     
265     our_office_id : function(cfg) 
266     {
267         cfg = cfg || {};
268         cfg.listeners = cfg.listeners  || {};
269         return Roo.apply({
270             xtype: 'ComboBoxAdder',
271             fieldLabel: "Office / Department",
272             
273             hiddenName:  'office_id',
274             name : 'office_id_name',
275             
276             qtip : "Select Office",
277             width: 300,
278             allowBlank : true,
279             triggerAction: 'all',
280             
281             
282             typeAhead: true,
283             forceSelection: true,
284             selectOnFocus:true,
285             
286             displayField:'name',
287             valueField : 'id',
288             
289             store:  {
290                 xtype : 'Store',
291                   // load using HTTP
292                 proxy: {
293                     xtype : 'HttpProxy',
294                     url: baseURL + '/Roo/Office.html',
295                     method: 'GET'
296                 },
297                 reader: Pman.Readers.Office,
298                 listeners : Roo.apply({
299                     loadexception : Pman.loadException
300                     }, cfg.storeListeners
301                 ),
302                 remoteSort : true,
303                 sortInfo: {
304                     field: 'name', direction: 'ASC'
305                 }
306             },
307             listeners : Roo.apply({
308                 adderclick : function()
309                 {
310                      
311                     var ncfg = {
312                         company_id : Pman.Login.authUser.company_id * 1,
313                         company_id_name:  Pman.Login.authUser.company_id_name,
314                         address: '',
315                         phone: '',
316                         fax: '',
317                         email: ''
318                     };
319
320                     
321                     Pman.Preview.tmpDisable();
322                     
323                     Pman.Dialog.Office.show(ncfg, function(data) {
324                         _this.setFromData(data);
325                         Pman.Preview.tmpEnable();
326                     }); 
327                 } 
328             }, cfg.listeners),
329            
330             //mode: 'local',
331             
332             tpl: new Ext.Template(
333                 '<div class="x-grid-cell-text x-btn button">',
334                     '<b>{name}</b> {address}',
335                 '</div>'
336             ),
337             queryParam: 'query[name]',
338             loadingText: "Searching...",
339             listWidth: 400,
340            
341             minChars: 2,
342             pageSize:20 
343              
344              
345              
346         }, cfg);
347     },
348     
349     /**
350      * Depreciated - use Pman.I18n directly
351      * 
352      */
353
354     country: function(cfg) { return Pman.I18n.country(cfg); }, 
355     language: function(cfg) { return Pman.I18n.language(cfg); }, 
356        
357     languageList : function(cfg) { return Pman.I18n.languageList(cfg); },
358     countryList : function(cfg) { return Pman.I18n.countryList(cfg); }
359      
360         
361 };