Pman.Dialog.CoreAutoSavePreview.bjs
[Pman.Core] / Pman.Dialog.CoreAutoSavePreview.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.CoreAutoSavePreview = {
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                     if(typeof(_this.data) != 'undefined'){
37                         _this.grid.footer.onClick('first');
38                     }
39                 }
40             },
41             background : false,
42             closable : false,
43             collapsible : false,
44             height : 500,
45             modal : true,
46             resizable : false,
47             title : "Saved Version",
48             width : 800,
49             items : [
50                 {
51                     xtype: 'GridPanel',
52                     xns: Roo,
53                     listeners : {
54                         activate : function() {
55                             _this.panel = this;
56                             if (_this.grid) {
57                                 _this.grid.footer.onClick('first');
58                             }
59                         }
60                     },
61                     background : false,
62                     fitContainer : true,
63                     fitToframe : true,
64                     region : 'west',
65                     tableName : 'Images',
66                     title : "Images",
67                     grid : {
68                         xtype: 'Grid',
69                         xns: Roo.grid,
70                         listeners : {
71                             render : function() 
72                             {
73                                 _this.grid = this; 
74                                 
75                                 if (_this.panel.active) {
76                                    this.footer.onClick('first');
77                                 }
78                             }
79                         },
80                         autoExpandColumn : 'event_when',
81                         loadMask : true,
82                         sm : {
83                             xtype: 'RowSelectionModel',
84                             xns: Roo.grid,
85                             listeners : {
86                                 afterselectionchange : function (_self)
87                                 {
88                                     var selected = this.getSelected();
89                                     
90                                     if (!selected) {
91                                         _this.viewPanel.setContent("Nothing Selected");
92                                         return;
93                                     }
94                                     
95                                     _this.viewPanel.load( { url : baseURL + "/Roo/Events", method : 'GET' }, {_id : selected.data.id, _retrieve_source : 1}, function(oElement, bSuccess, oResponse){
96                                         
97                                         _this.source = '';
98                                         
99                                         var res = Roo.decode(oResponse.responseText);
100                                         
101                                         if(!bSuccess || !res.success){
102                                             _this.viewPanel.setContent("Load data failed?!");
103                                         }
104                                         
105                                         if(typeof(res.data) === 'string'){
106                                             _this.viewPanel.setContent(res.data);
107                                             return;
108                                         }
109                                         
110                                         if(!_this.data.successFn){
111                                             Roo.MessageBox.alert('Error', 'Please setup the successFn');
112                                             return;
113                                         }
114                                         
115                                         _this.source = _this.data.successFn(res);
116                                 
117                                         _this.viewPanel.setContent(_this.source);
118                                         
119                                     });
120                                 }
121                             },
122                             singleSelect : true
123                         },
124                         dataSource : {
125                             xtype: 'Store',
126                             xns: Roo.data,
127                             listeners : {
128                                 beforeload : function (_self, o)
129                                 {
130                                     o.params = o.params || {};
131                                     
132                                     if(typeof(_this.data) == 'undefined'){
133                                         this.removeAll();
134                                         return false;
135                                     }
136                                 
137                                     var d = Roo.apply({}, _this.data);
138                                     delete d.successFn;
139                                     
140                                     Roo.apply(o.params, d);
141                                     
142                                 }
143                             },
144                             remoteSort : true,
145                             sortInfo : { field : 'event_when', direction: 'DESC' },
146                             proxy : {
147                                 xtype: 'HttpProxy',
148                                 xns: Roo.data,
149                                 method : 'GET',
150                                 url : baseURL + '/Roo/Events.php'
151                             },
152                             reader : {
153                                 xtype: 'JsonReader',
154                                 xns: Roo.data,
155                                 id : 'id',
156                                 root : 'data',
157                                 totalProperty : 'total',
158                                 fields : [
159                                     {
160                                         'name': 'id',
161                                         'type': 'int'
162                                     },
163                                     {
164                                         'name': 'event_when',
165                                         'type': 'string'
166                                     }
167                                 ]
168                             }
169                         },
170                         footer : {
171                             xtype: 'PagingToolbar',
172                             xns: Roo,
173                             displayInfo : false,
174                             pageSize : 25
175                         },
176                         colModel : [
177                             {
178                                 xtype: 'ColumnModel',
179                                 xns: Roo.grid,
180                                 dataIndex : 'event_when',
181                                 header : 'Date',
182                                 width : 100,
183                                 renderer : function(v) { return String.format('{0}', v ? v.format('Y-m-d H:i:s') : ''); }
184                             }
185                         ]
186                     }
187                 },
188                 {
189                     xtype: 'ContentPanel',
190                     xns: Roo,
191                     listeners : {
192                         render : function (_self)
193                         {
194                             _this.viewPanel = _self;
195                         }
196                     },
197                     autoScroll : true,
198                     background : false,
199                     fitContainer : true,
200                     fitToFrame : true,
201                     region : 'center'
202                 }
203             ],
204             center : {
205                 xtype: 'LayoutRegion',
206                 xns: Roo
207             },
208             west : {
209                 xtype: 'LayoutRegion',
210                 xns: Roo,
211                 split : true,
212                 width : 200
213             },
214             buttons : [
215                 {
216                     xtype: 'Button',
217                     xns: Roo,
218                     listeners : {
219                         click : function() {
220                             _this.dialog.hide();
221                         }
222                     },
223                     text : "Cancel"
224                 },
225                 {
226                     xtype: 'Button',
227                     xns: Roo,
228                     listeners : {
229                         click : function() {
230                         
231                             _this.dialog.hide();
232                             
233                             if (_this.callback) {
234                                 _this.callback.call(this, _this.source);
235                             }
236                         }
237                     },
238                     text : "OK"
239                 }
240             ]
241         });
242     }
243 };