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