Pman.Dialog.AdminEnumImages.bjs
[Pman.Admin] / Pman.Dialog.AdminEnumImages.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5 Pman.Dialog.AdminEnumImages = {
6
7     dialog : false,
8     callback:  false,
9
10     show : function(data, cb)
11     {
12         if (!this.dialog) {
13             this.create();
14         }
15
16         this.callback = cb;
17         this.data = data;
18         this.dialog.show(this.data._el);
19         if (this.form) {
20            this.form.reset();
21            this.form.setValues(data);
22            this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });
23         }
24
25     },
26
27     create : function()
28     {
29         var _this = this;
30         this.dialog = Roo.factory({
31             xtype: 'LayoutDialog',
32             xns: Roo,
33             listeners : {
34                 show : function (_self)
35                 {
36                     _this.grid.footer.onClick('first');
37                 }
38             },
39             height : 500,
40             modal : true,
41             title : "Add / Edit Images",
42             width : 900,
43             items : [
44                 {
45                     xtype: 'GridPanel',
46                     xns: Roo,
47                     listeners : {
48                         activate : function() {
49                             _this.panel = this;
50                             if (_this.grid) {
51                                 _this.grid.footer.onClick('first');
52                             }
53                         }
54                     },
55                     background : false,
56                     fitContainer : true,
57                     fitToframe : true,
58                     region : 'center',
59                     tableName : 'Images',
60                     title : "Images",
61                     grid : {
62                         xtype: 'Grid',
63                         xns: Roo.grid,
64                         autoExpandColumn : 'title',
65                         loadMask : true,
66                         listeners : {
67                             render : function() { 
68                                 _this.grid = this; 
69                                 //_this.dialog = Pman.Dialog.FILL_IN
70                                 if (_this.panel.active) {
71                                    this.footer.onClick('first');
72                                 }
73                             },
74                             rowdblclick : function (_self, rowIndex, e)
75                             {
76                               
77                                var s =  _self.getDataSource().getAt(rowIndex);
78                                  Pman.Dialog.PressReleaseImage.show(s.data, function() {
79                                             _this.grid.footer.onClick('first');
80                                            }); 
81                             }
82                         },
83                         dataSource : {
84                             xtype: 'Store',
85                             xns: Roo.data,
86                             listeners : {
87                                 beforeload : function (_self, o)
88                                 {
89                                     //o.params.ontable = 'Companies';
90                                     
91                                   //   o.params.imgtype = 'PressRelease';
92                                     
93                                     o.params = o.params || {};
94                                     Roo.log(_this);
95                                     
96                                 },
97                                 load : function (_self, records, options)
98                                 {
99                                  _this.panel.el.unmask();
100                                 }
101                             },
102                             remoteSort : true,
103                             sortInfo : { field: 'created' , direction: 'DESC' },
104                             reader : {
105                                 xtype: 'JsonReader',
106                                 xns: Roo.data,
107                                 id : 'id',
108                                 root : 'data',
109                                 totalProperty : 'total',
110                                 fields : [
111                                     {
112                                         'name': 'id',
113                                         'type': 'int'
114                                     },
115                                     {
116                                         'name': 'filename',
117                                         'type': 'string'
118                                     },
119                                     {
120                                         'name': 'ontable',
121                                         'type': 'string'
122                                     },
123                                     {
124                                         'name': 'onid',
125                                         'type': 'int'
126                                     },
127                                     {
128                                         'name': 'mimetype',
129                                         'type': 'string'
130                                     },
131                                     {
132                                         'name': 'width',
133                                         'type': 'int'
134                                     },
135                                     {
136                                         'name': 'height',
137                                         'type': 'int'
138                                     },
139                                     {
140                                         'name': 'filesize',
141                                         'type': 'int'
142                                     },
143                                     {
144                                         'name': 'displayorder',
145                                         'type': 'int'
146                                     },
147                                     {
148                                         'name': 'language',
149                                         'type': 'string'
150                                     },
151                                     {
152                                         'name': 'parent_image_id',
153                                         'type': 'int'
154                                     },
155                                     {
156                                         'name': 'created',
157                                         'type': 'date',
158                                         'dateFormat' : 'Y-m-d H:i:s'
159                                     },
160                                     {
161                                         'name': 'imgtype',
162                                         'type': 'string'
163                                     },
164                                     {
165                                         'name': 'linkurl',
166                                         'type': 'string'
167                                     },
168                                     {
169                                         'name': 'descript',
170                                         'type': 'string'
171                                     },
172                                     {
173                                         'name': 'title',
174                                         'type': 'string'
175                                     }
176                                 ]
177                             },
178                             proxy : {
179                                 xtype: 'HttpProxy',
180                                 xns: Roo.data,
181                                 method : 'GET',
182                                 url : baseURL + '/Roo/Images.php'
183                             }
184                         },
185                         footer : {
186                             xtype: 'PagingToolbar',
187                             xns: Roo,
188                             pageSize : 25,
189                             displayInfo : true,
190                             displayMsg : "Displaying Images  {0} - {1} of {2}",
191                             emptyMsg : "No Images found"
192                         },
193                         toolbar : {
194                             xtype: 'Toolbar',
195                             xns: Roo,
196                             items : [
197                                 {
198                                     xtype: 'Button',
199                                     xns: Roo.Toolbar,
200                                     listeners : {
201                                         click : function()
202                                                 {
203                                                     
204                                               var sel = Pman.Tab.PressReleaseCompanies  ? Pman.Tab.PressReleaseCompanies.grid.getSelectionModel().getSelected() : false
205                                              
206                                             Pman.Dialog.Image.show( {
207                                                id : 0, 
208                                                 ontable: 'Companies', 
209                                                  onid: sel.data.id,
210                                             imgtype : 'PressRelease'
211                                              }, 
212                                             function(data) {
213                                                         if (!data) { return; } 
214                                              Pman.Dialog.PressReleaseImage.show( data, function() {
215                                                           _this.grid.footer.onClick('first');
216                                         
217                                                     }); 
218                                                         }); 
219                                         
220                                                 }
221                                     },
222                                     cls : 'x-btn-text-icon',
223                                     text : "Add",
224                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
225                                 },
226                                 {
227                                     xtype: 'Button',
228                                     xns: Roo,
229                                     listeners : {
230                                         click : function()
231                                         {
232                                             var s = _this.grid.getSelectionModel().getSelections();
233                                             if (!s || s.length != 1) {
234                                                 Roo.MessageBox.alert("Error", "Select a single image to edit");
235                                                return;
236                                              }
237                                              var data = _this.grid.getDataSource().getById(s[0].data.id).data;
238                                             
239                                                      Pman.Dialog.PressReleaseImage.show(data, function() {
240                                                         _this.grid.footer.onClick('first');
241                                                        }); 
242                                                     
243                                                 }
244                                     },
245                                     cls : 'x-btn-text-icon',
246                                     text : "Edit",
247                                     icon : Roo.rootURL + 'images/default/tree/leaf.gif'
248                                 },
249                                 {
250                                     xtype: 'Button',
251                                     xns: Roo.Toolbar,
252                                     listeners : {
253                                         click : function()
254                                                 {
255                                                 Pman.genericDelete(_this, 'Images'); 
256                                                 }
257                                     },
258                                     cls : 'x-btn-text-icon',
259                                     text : "Delete",
260                                     icon : rootURL + '/Pman/templates/images/trash.gif'
261                                 }
262                             ]
263                         },
264                         colModel : [
265                             {
266                                 xtype: 'ColumnModel',
267                                 xns: Roo.grid,
268                                 header : 'Created',
269                                 width : 100,
270                                 dataIndex : 'created',
271                                 renderer : function(v,x,r) {
272                                        return String.format('{0}<br/><i>{1}</i><br/>{2}<br/><i>{3}x{4}</i>',
273                                             v.format('d/M/Y'), r.data.mimetype, r.data.filename,
274                                     r.data.width, r.data.height
275                                     ); 
276                                 },
277                                 sortable : true
278                             },
279                             {
280                                 xtype: 'ColumnModel',
281                                 xns: Roo.grid,
282                                 dataIndex : 'id',
283                                 header : 'Image',
284                                 width : 100,
285                                 renderer : function(v,x,r) { return String.format('<img src="{0}/Images/Thumb/100/{1}/{2}" width="100">', baseURL, v, r.data.filename); }
286                             },
287                             {
288                                 xtype: 'ColumnModel',
289                                 xns: Roo.grid,
290                                 dataIndex : 'title',
291                                 header : 'Details',
292                                 width : 100,
293                                 renderer : function(v,x,r) {
294                                      var surl = r.json.url.replace(/\/release.php\/Images\//, '/i/').replace(/\/([0-9]+)\/.*$/, '/$1');;
295                                      var svurl = r.json.url_view.replace(/\/release.php\/Images\//, '/i/').replace(/\/([0-9]+)\/.*$/, '/$1');;
296                                       return String.format(
297                                           'Download Url : <a href="http://{0}{1}" target="_new">http://{0}{1}</a>' + 
298                                           '<br/>View Url : <a href="http://{0}{2}" target="_new">http://{0}{2}</a>' + 
299                                           '<br/><b>{3}</b><br/>{4}</i>', 
300                                           window.location.host, surl, svurl,
301                                            v, r.json.descript); 
302                                      
303                                     }
304                             }
305                         ]
306                     }
307                 }
308             ],
309             center : {
310                 xtype: 'LayoutRegion',
311                 xns: Roo
312             },
313             buttons : [
314                 {
315                     xtype: 'Button',
316                     xns: Roo,
317                     listeners : {
318                         click : function (_self, e)
319                         {
320                             _this.dialog.hide();
321                             _this.callback(true);
322                         }
323                     },
324                     text : "Cancel"
325                 },
326                 {
327                     xtype: 'Button',
328                     xns: Roo,
329                     listeners : {
330                         click : function (_self, e)
331                         {
332                             _this.dialog.hide();
333                             _this.callback(true);
334                         }
335                     },
336                     text : "OK"
337                 }
338             ]
339         });
340     }
341 };