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                                         _this.data.successFn();
119                                         
120                                     });
121                                 }
122                             },
123                             singleSelect : true
124                         },
125                         dataSource : {
126                             xtype: 'Store',
127                             xns: Roo.data,
128                             listeners : {
129                                 beforeload : function (_self, o)
130                                 {
131                                     o.params = o.params || {};
132                                     
133                                     if(typeof(_this.data) == 'undefined'){
134                                         this.removeAll();
135                                         return false;
136                                     }
137                                     Roo.log(_this.data);
138                                     o.params.action = 'AUTOSAVE';
139                                 }
140                             },
141                             remoteSort : true,
142                             sortInfo : { field : 'event_when', direction: 'DESC' },
143                             proxy : {
144                                 xtype: 'HttpProxy',
145                                 xns: Roo.data,
146                                 method : 'GET',
147                                 url : baseURL + '/Roo/Events.php'
148                             },
149                             reader : {
150                                 xtype: 'JsonReader',
151                                 xns: Roo.data,
152                                 id : 'id',
153                                 root : 'data',
154                                 totalProperty : 'total',
155                                 fields : [
156                                     {
157                                         'name': 'id',
158                                         'type': 'int'
159                                     },
160                                     {
161                                         'name': 'event_when',
162                                         'type': 'string'
163                                     }
164                                 ]
165                             }
166                         },
167                         footer : {
168                             xtype: 'PagingToolbar',
169                             xns: Roo,
170                             displayInfo : false,
171                             pageSize : 25
172                         },
173                         colModel : [
174                             {
175                                 xtype: 'ColumnModel',
176                                 xns: Roo.grid,
177                                 dataIndex : 'event_when',
178                                 header : 'Date',
179                                 width : 100,
180                                 renderer : function(v) { return String.format('{0}', v ? v.format('Y-m-d H:i:s') : ''); }
181                             }
182                         ]
183                     }
184                 },
185                 {
186                     xtype: 'ContentPanel',
187                     xns: Roo,
188                     listeners : {
189                         render : function (_self)
190                         {
191                             _this.viewPanel = _self;
192                         }
193                     },
194                     autoScroll : true,
195                     background : false,
196                     fitContainer : true,
197                     fitToFrame : true,
198                     region : 'center'
199                 }
200             ],
201             center : {
202                 xtype: 'LayoutRegion',
203                 xns: Roo
204             },
205             west : {
206                 xtype: 'LayoutRegion',
207                 xns: Roo,
208                 split : true,
209                 width : 200
210             },
211             buttons : [
212                 {
213                     xtype: 'Button',
214                     xns: Roo,
215                     listeners : {
216                         click : function() {
217                             _this.dialog.hide();
218                         }
219                     },
220                     text : "Cancel"
221                 },
222                 {
223                     xtype: 'Button',
224                     xns: Roo,
225                     listeners : {
226                         click : function() {
227                         
228                             _this.dialog.hide();
229                             
230                             if (_this.callback) {
231                                 _this.callback.call(this, _this.source);
232                             }
233                         }
234                     },
235                     text : "OK"
236                 }
237             ]
238         });
239     }
240 };