knitkit 2.0.5 → 2.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/app/controllers/knitkit/erp_app/desktop/app_controller.rb +5 -8
  2. data/app/controllers/knitkit/erp_app/desktop/articles_controller.rb +11 -8
  3. data/app/controllers/knitkit/erp_app/desktop/content_controller.rb +26 -4
  4. data/app/controllers/knitkit/erp_app/desktop/file_assets_controller.rb +49 -35
  5. data/app/controllers/knitkit/erp_app/desktop/image_assets_controller.rb +30 -21
  6. data/app/controllers/knitkit/erp_app/desktop/theme_controller.rb +41 -32
  7. data/app/controllers/knitkit/erp_app/desktop/website_controller.rb +0 -6
  8. data/app/controllers/knitkit/erp_app/desktop/website_section_controller.rb +42 -6
  9. data/app/{models → mailers}/website_inquiry_mailer.rb +0 -0
  10. data/app/models/article.rb +4 -0
  11. data/app/models/content.rb +0 -4
  12. data/app/models/theme.rb +3 -3
  13. data/app/models/website.rb +44 -17
  14. data/app/views/knitkit/website_sections/index.html.erb +1 -1
  15. data/app/views/layouts/knitkit/base.html.erb +6 -0
  16. data/app/views/shared/knitkit/_footer.html.erb +2 -2
  17. data/app/widgets/signup/base.rb +0 -2
  18. data/db/data_migrations/20120809020508_update_website_and_configuration.rb +77 -0
  19. data/lib/knitkit/engine.rb +4 -0
  20. data/lib/knitkit/extensions.rb +4 -1
  21. data/lib/knitkit/extensions/action_controller/theme_support/acts_as_themed_controller.rb +36 -33
  22. data/lib/knitkit/extensions/action_mailer/theme_support/acts_as_themed_mailer.rb +60 -0
  23. data/lib/knitkit/extensions/active_record/acts_as_commentable.rb +9 -4
  24. data/lib/knitkit/extensions/active_record/acts_as_document.rb +1 -1
  25. data/lib/knitkit/extensions/compass_ae/widgets/base.rb +21 -1
  26. data/lib/knitkit/extensions/compass_ae/widgets/widget_proxy_controller.rb +26 -0
  27. data/lib/knitkit/extensions/railties/action_view/base.rb +11 -0
  28. data/lib/knitkit/extensions/railties/action_view/helpers/blog_helper.rb +62 -0
  29. data/lib/knitkit/extensions/railties/action_view/helpers/content_helper.rb +83 -0
  30. data/lib/knitkit/extensions/railties/action_view/helpers/knitkit_helper.rb +67 -0
  31. data/lib/knitkit/extensions/railties/action_view/helpers/menu_helper.rb +71 -0
  32. data/lib/knitkit/version.rb +1 -1
  33. data/public/images/knitkit/close.png +0 -0
  34. data/public/javascripts/erp_app/desktop/applications/knitkit/articles_grid_panel.js +150 -400
  35. data/public/javascripts/erp_app/desktop/applications/knitkit/center_region.js +687 -593
  36. data/public/javascripts/erp_app/desktop/applications/knitkit/east_region.js +1 -2
  37. data/public/javascripts/erp_app/desktop/applications/knitkit/file_assets_panel.js +39 -15
  38. data/public/javascripts/erp_app/desktop/applications/knitkit/image_assets_data_view.js +1 -1
  39. data/public/javascripts/erp_app/desktop/applications/knitkit/image_assets_panel.js +65 -126
  40. data/public/javascripts/erp_app/desktop/applications/knitkit/module.js +65 -1
  41. data/public/javascripts/erp_app/desktop/applications/knitkit/section_articles_grid_panel.js +265 -183
  42. data/public/javascripts/erp_app/desktop/applications/knitkit/themes_tree_panel.js +24 -9
  43. data/public/javascripts/erp_app/desktop/applications/knitkit/versions_grid_panel.js +631 -595
  44. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/document.js +265 -0
  45. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/host.js +133 -0
  46. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/menu.js +174 -0
  47. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/section.js +399 -0
  48. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/website.js +165 -0
  49. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/website_nav_items.js +266 -0
  50. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/west_region.js +1224 -0
  51. data/public/javascripts/knitkit/inline_editing.js +136 -0
  52. data/public/stylesheets/extjs/resources/css/knitkit_extjs_4.css +1 -2
  53. data/public/stylesheets/knitkit/inline_editing.css +88 -0
  54. data/public/stylesheets/knitkit/style.css +1 -1
  55. metadata +47 -31
  56. data/lib/knitkit/extensions/railties/action_view.rb +0 -199
  57. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region.js +0 -2725
@@ -1,627 +1,721 @@
1
- Ext.define("Compass.ErpApp.Desktop.Applications.Knitkit.CenterRegion",{
2
- extend:"Ext.panel.Panel",
3
- alias:'widget.knitkit_centerregion',
4
- ckEditorToolbar:[
5
- ['Source','-','CompassSave','Preview','Print'],
6
- ['Cut','Copy','Paste','PasteText','PasteFromWord'],
7
- ['Undo','Redo'],
8
- ['Find','Replace'],
9
- ['SpellChecker','-','SelectAll'],
10
- ['TextColor','BGColor'],
11
- ['Bold','Italic','Underline','Strike'],
12
- ['Subscript','Superscript','-','jwplayer'],
13
- ['Table','NumberedList','BulletedList'],
14
- ['Outdent','Indent','Blockquote'],
15
- ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
16
- ['BidiLtr','BidiRtl'],
17
- ['Link','Unlink','Anchor'],
18
- ['HorizontalRule','SpecialChar','PageBreak'],
19
- ['ShowBlocks','RemoveFormat'],
20
- ['Styles','Format','Font','FontSize' ],
21
- ['Maximize','-','About']
22
- ],
23
-
24
- setWindowStatus : function(status){
25
- this.findParentByType('statuswindow').setStatus(status);
26
- },
27
-
28
- clearWindowStatus : function(){
29
- this.findParentByType('statuswindow').clearStatus();
30
- },
31
-
32
- viewSectionLayout : function(title, template){
33
- this.workArea.add({
34
- title:title + ' - Layout',
35
- disableToolbar:true,
36
- xtype:'codemirror',
37
- parser:'rhtml',
38
- sourceCode:template,
39
- closable:true
40
- });
41
- this.workArea.setActiveTab(this.workArea.items.length - 1);
42
- return false;
43
- },
44
-
45
- saveSectionLayout : function(sectionId, content){
46
- var self = this;
47
- this.setWindowStatus('Saving...');
48
- Ext.Ajax.request({
49
- url: '/knitkit/erp_app/desktop/section/save_layout',
50
- method: 'POST',
51
- params:{
52
- id:sectionId,
53
- content:content
54
- },
55
- success: function(response) {
56
- self.clearWindowStatus();
57
- var obj = Ext.decode(response.responseText);
58
- if(obj.success){
59
- var activeTab = self.workArea.getActiveTab();
60
- activeTab.query('knitkit_versionswebsitesectiongridpanel')[0].store.load();
61
- }
62
- else{
63
- Ext.Msg.alert('Error', obj.message);
1
+ Ext.define("Compass.ErpApp.Desktop.Applications.Knitkit.CenterRegion", {
2
+ extend:"Ext.panel.Panel",
3
+ alias:'widget.knitkit_centerregion',
4
+ ckEditorToolbar:[
5
+ ['Source', '-', 'Preview', 'Print'],
6
+ ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord'],
7
+ ['Undo', 'Redo'],
8
+ ['Find', 'Replace'],
9
+ ['SpellChecker', '-', 'SelectAll'],
10
+ ['TextColor', 'BGColor'],
11
+ ['Bold', 'Italic', 'Underline', 'Strike'],
12
+ ['Subscript', 'Superscript', '-', 'jwplayer'],
13
+ ['Table', 'NumberedList', 'BulletedList'],
14
+ ['Outdent', 'Indent', 'Blockquote'],
15
+ ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
16
+ ['BidiLtr', 'BidiRtl'],
17
+ ['Link', 'Unlink', 'Anchor'],
18
+ ['HorizontalRule', 'SpecialChar', 'PageBreak'],
19
+ ['ShowBlocks', 'RemoveFormat'],
20
+ ['Styles', 'Format', 'Font', 'FontSize' ],
21
+ ['Maximize', '-', 'About']
22
+ ],
23
+
24
+ setWindowStatus:function (status) {
25
+ this.findParentByType('statuswindow').setStatus(status);
26
+ },
27
+
28
+ clearWindowStatus:function () {
29
+ this.findParentByType('statuswindow').clearStatus();
30
+ },
31
+
32
+ viewSectionLayout:function (title, template) {
33
+ this.workArea.add({
34
+ title:title + ' - Layout',
35
+ disableToolbar:true,
36
+ xtype:'codemirror',
37
+ parser:'rhtml',
38
+ sourceCode:template,
39
+ closable:true
40
+ });
41
+ this.workArea.setActiveTab(this.workArea.items.length - 1);
42
+ return false;
43
+ },
44
+
45
+ saveSectionLayout:function (sectionId, content) {
46
+ var self = this;
47
+ this.setWindowStatus('Saving...');
48
+ Ext.Ajax.request({
49
+ url:'/knitkit/erp_app/desktop/section/save_layout',
50
+ method:'POST',
51
+ params:{
52
+ id:sectionId,
53
+ content:content
54
+ },
55
+ success:function (response) {
56
+ self.clearWindowStatus();
57
+ var obj = Ext.decode(response.responseText);
58
+ if (obj.success) {
59
+ var activeTab = self.workArea.getActiveTab();
60
+ var versionsGrid = activeTab.down('knitkit_versionswebsitesectiongridpanel');
61
+ if (!Ext.isEmpty(versionsGrid)) {
62
+ versionsGrid.store.load();
63
+ }
64
+ }
65
+ else {
66
+ Ext.Msg.alert('Error', obj.message);
67
+ }
68
+ },
69
+ failure:function (response) {
70
+ self.clearWindowStatus();
71
+ Ext.Msg.alert('Error', 'Error saving layout');
72
+ }
73
+ });
74
+ },
75
+
76
+ editSectionLayout:function (sectionName, websiteId, websiteSectionId, content, tbarItems) {
77
+ var self = this;
78
+ var itemId = 'section-' + websiteSectionId;
79
+ var item = this.workArea.query('#' + itemId).first();
80
+
81
+ if (Compass.ErpApp.Utility.isBlank(item)) {
82
+ item = Ext.create("Ext.panel.Panel", {
83
+ layout:'border',
84
+ title:sectionName,
85
+ save:function (comp) {
86
+ var content = comp.down('codemirror').getValue();
87
+ self.saveSectionLayout(websiteSectionId, content);
88
+ },
89
+ closable:true,
90
+ itemId:itemId,
91
+ items:[
92
+ {
93
+ title:sectionName + ' - Layout',
94
+ tbarItems:tbarItems,
95
+ disableSave:true,
96
+ xtype:'codemirror',
97
+ parser:'erb',
98
+ region:'center',
99
+ sourceCode:content
100
+ },
101
+ {
102
+ xtype:'knitkit_versionswebsitesectiongridpanel',
103
+ websiteSectionId:websiteSectionId,
104
+ region:'south',
105
+ height:150,
106
+ collapsible:true,
107
+ centerRegion:self,
108
+ siteId:websiteId
109
+ }
110
+ ],
111
+ listeners:{
112
+ 'show':function (panel) {
113
+ Ext.getCmp('knitkitWestRegion').selectWebsite(websiteId);
114
+ }
115
+ }
116
+ });
117
+
118
+ this.workArea.add(item);
64
119
  }
65
- },
66
- failure: function(response) {
67
- self.clearWindowStatus();
68
- Ext.Msg.alert('Error', 'Error saving layout');
69
- }
70
- });
71
- },
72
-
73
- editSectionLayout : function(sectionName, websiteId, websiteSectionId, content, tbarItems){
74
- var self = this;
75
- var itemId = 'section-'+websiteSectionId;
76
- var item = this.workArea.query('#'+itemId).first();
77
-
78
- if(Compass.ErpApp.Utility.isBlank(item)){
79
- item = Ext.create("Ext.panel.Panel",{
80
- layout:'border',
81
- title:sectionName,
82
- closable:true,
83
- itemId:itemId,
84
- items:[
85
- {
86
- title:sectionName + ' - Layout',
87
- tbarItems:tbarItems,
88
- xtype:'codemirror',
89
- parser:'erb',
90
- region:'center',
91
- sourceCode:content,
92
- closable:true,
93
- listeners:{
94
- 'save':function(codeMirror, content){
95
- self.saveSectionLayout(websiteSectionId, content);
120
+
121
+ this.workArea.setActiveTab(item);
122
+ return false;
123
+ },
124
+
125
+ saveTemplateFile:function (path, content) {
126
+ var self = this;
127
+ this.setWindowStatus('Saving...');
128
+ Ext.Ajax.request({
129
+ url:'/knitkit/erp_app/desktop/theme/update_file',
130
+ method:'POST',
131
+ params:{
132
+ node:path,
133
+ content:content
134
+ },
135
+ success:function (response) {
136
+ var obj = Ext.decode(response.responseText);
137
+ self.clearWindowStatus();
138
+ if (!obj.success) {
139
+ Ext.Msg.alert('Error', obj.message);
140
+ }
141
+ },
142
+ failure:function (response) {
143
+ self.clearWindowStatus();
144
+ Ext.Msg.alert('Error', 'Error saving contents');
96
145
  }
97
- }
98
- },
99
- {
100
- xtype:'knitkit_versionswebsitesectiongridpanel',
101
- websiteSectionId:websiteSectionId,
102
- region:'south',
103
- height:150,
104
- collapsible:true,
105
- centerRegion:self,
106
- siteId:websiteId
146
+ });
147
+ },
148
+
149
+ editTemplateFile:function (node, content, tbarItems, themeId) {
150
+ var self = this;
151
+ var fileName = node.data.id.split('/').pop().split('.')[0];
152
+ var fileType = node.data.id.split('.').pop();
153
+ var itemId = fileName + themeId;
154
+ var item = this.workArea.query('#' + itemId).first();
155
+
156
+ if (Compass.ErpApp.Utility.isBlank(item)) {
157
+ item = Ext.create('Ext.panel.Panel', {
158
+ closable:true,
159
+ title:fileName,
160
+ itemId:itemId,
161
+ layout:'fit',
162
+ save:function (comp) {
163
+ var content = comp.down('codemirror').getValue();
164
+ self.saveTemplateFile(node.data.id, content);
165
+ },
166
+ items:[
167
+ {
168
+ tbarItems:tbarItems,
169
+ disableSave:true,
170
+ xtype:'codemirror',
171
+ parser:fileType,
172
+ sourceCode:content
173
+ }
174
+ ]
175
+ });
176
+
177
+ this.workArea.add(item);
107
178
  }
108
- ],
109
- listeners:{
110
- 'show':function(panel){
111
- Ext.getCmp('knitkitWestRegion').selectWebsite(websiteId);
112
- }
179
+
180
+ this.workArea.setActiveTab(item);
181
+ return false;
182
+ },
183
+
184
+ saveExcerpt:function (id, content, siteId) {
185
+ var self = this;
186
+ this.setWindowStatus('Saving...');
187
+ Ext.Ajax.request({
188
+ url:'/knitkit/erp_app/desktop/content/save_excerpt',
189
+ method:'POST',
190
+ params:{
191
+ id:id,
192
+ html:content,
193
+ site_id:siteId
194
+ },
195
+ success:function (response) {
196
+ var obj = Ext.decode(response.responseText);
197
+ if (obj.success) {
198
+ self.clearWindowStatus();
199
+ var activeTab = self.workArea.getActiveTab();
200
+ var panel = activeTab.query('knitkit_versionsbloggridpanel');
201
+ if (panel.length == 0) {
202
+ panel = activeTab.query('knitkit_nonpublishedversionswebsitesectiongridpanel');
203
+ }
204
+ panel[0].getStore().load();
205
+ }
206
+ else {
207
+ Ext.Msg.alert('Error', 'Error saving excerpt');
208
+ self.clearWindowStatus();
209
+ }
210
+ },
211
+ failure:function (response) {
212
+ self.clearWindowStatus();
213
+ Ext.Msg.alert('Error', 'Error saving excerpt');
214
+ }
215
+ });
216
+ },
217
+
218
+ editExcerpt:function (title, id, content, siteId, contentGridStore) {
219
+ var self = this;
220
+ var itemId = 'editExcerpt-' + id;
221
+ var item = this.workArea.query('#' + itemId).first();
222
+
223
+ if (Compass.ErpApp.Utility.isBlank(item)) {
224
+ var ckEditor = Ext.create("Compass.ErpApp.Shared.CKeditor", {
225
+ autoHeight:true,
226
+ value:content,
227
+ ckEditorConfig:{
228
+ extraPlugins:'jwplayer',
229
+ toolbar:self.ckEditorToolbar
230
+ }
231
+ });
232
+
233
+ var items = [
234
+ {
235
+ xtype:'panel',
236
+ layout:'fit',
237
+ split:true,
238
+ region:'center',
239
+ items:ckEditor,
240
+ autoDestroy:true
241
+ }
242
+ ];
243
+
244
+ if (!Compass.ErpApp.Utility.isBlank(siteId)) {
245
+ items.push({
246
+ xtype:'knitkit_versionsbloggridpanel',
247
+ contentId:id,
248
+ region:'south',
249
+ height:150,
250
+ collapsible:true,
251
+ centerRegion:self,
252
+ siteId:siteId
253
+ });
254
+ }
255
+ else {
256
+ items.push({
257
+ xtype:'knitkit_nonpublishedversionswebsitesectiongridpanel',
258
+ contentId:id,
259
+ region:'south',
260
+ height:150,
261
+ collapsible:true,
262
+ centerRegion:self
263
+ });
264
+ }
265
+
266
+ item = Ext.create("Ext.panel.Panel", {
267
+ layout:'border',
268
+ title:title,
269
+ closable:true,
270
+ items:items,
271
+ save:function (comp) {
272
+ if (currentUser.hasApplicationCapability('knitkit', {
273
+ capability_type_iid:'edit_html',
274
+ resource:'Article'
275
+ })) {
276
+ var content = comp.down('ckeditor').getValue();
277
+ self.saveExcerpt(id, content, siteId);
278
+ contentGridStore.load();
279
+ } else {
280
+ currentUser.showInvalidAccess();
281
+ }
282
+ },
283
+ itemId:itemId,
284
+ listeners:{
285
+ 'show':function (panel) {
286
+ if (!Compass.ErpApp.Utility.isBlank(siteId)) {
287
+ Ext.getCmp('knitkitWestRegion').selectWebsite(siteId);
288
+ }
289
+ }
290
+ }
291
+ });
292
+
293
+ this.workArea.add(item);
113
294
  }
114
- });
115
295
 
116
- this.workArea.add(item);
117
- }
296
+ this.workArea.setActiveTab(item);
297
+ },
118
298
 
119
- this.workArea.setActiveTab(item);
120
- return false;
121
- },
122
-
123
- saveTemplateFile : function(path, content){
124
- var self = this;
125
- this.setWindowStatus('Saving...');
126
- Ext.Ajax.request({
127
- url: '/knitkit/erp_app/desktop/theme/update_file',
128
- method: 'POST',
129
- params:{
130
- node:path,
131
- content:content
132
- },
133
- success: function(response) {
134
- var obj = Ext.decode(response.responseText);
135
- self.clearWindowStatus();
136
- if(!obj.success){
137
- Ext.Msg.alert('Error', obj.message);
299
+
300
+ showImage:function (node, themeId) {
301
+ var self = this;
302
+ var fileName = node.data.id.split('/').pop().split('.')[0];
303
+ var fileType = node.data.id.split('.').pop();
304
+ var itemId = fileName + themeId;
305
+ var item = this.workArea.query('#' + itemId).first();
306
+
307
+ if (Compass.ErpApp.Utility.isBlank(item)) {
308
+ item = Ext.create('Ext.panel.Panel', {
309
+ closable:true,
310
+ title:fileName + '.' + fileType,
311
+ itemId:itemId,
312
+ layout:'fit',
313
+ html:'<img src="' + node.data.url + '" />'
314
+ });
315
+
316
+ this.workArea.add(item);
138
317
  }
139
- },
140
- failure: function(response) {
141
- self.clearWindowStatus();
142
- Ext.Msg.alert('Error', 'Error saving contents');
143
- }
144
- });
145
- },
146
-
147
- editTemplateFile : function(node, content, tbarItems, themeId){
148
- var self = this;
149
- var fileName = node.data.id.split('/').pop().split('.')[0];
150
- var fileType = node.data.id.split('.').pop();
151
- var itemId = fileName+themeId;
152
- var item = this.workArea.query('#'+itemId).first();
153
-
154
- if(Compass.ErpApp.Utility.isBlank(item)){
155
- item = Ext.create('Ext.panel.Panel',{
156
- closable:true,
157
- title:fileName,
158
- itemId:itemId,
159
- layout:'fit',
160
- items:[{
161
- tbarItems:tbarItems,
162
- xtype:'codemirror',
163
- parser:fileType,
164
- sourceCode:content,
165
- closable:true,
166
- listeners:{
167
- 'save':function(codeMirror, content){
168
- self.saveTemplateFile(node.data.id, content);
318
+
319
+ this.workArea.setActiveTab(item);
320
+ return false;
321
+ },
322
+
323
+ saveContent:function (id, content, contentType, siteId) {
324
+ var self = this;
325
+ this.setWindowStatus('Saving...');
326
+ Ext.Ajax.request({
327
+ url:'/knitkit/erp_app/desktop/content/update',
328
+ method:'POST',
329
+ params:{
330
+ id:id,
331
+ html:content,
332
+ site_id:siteId
333
+ },
334
+ success:function (response) {
335
+ var obj = Ext.decode(response.responseText);
336
+ if (obj.success) {
337
+ self.clearWindowStatus();
338
+ if (!Compass.ErpApp.Utility.isBlank(contentType)) {
339
+ var activeTab = self.workArea.getActiveTab();
340
+ var versionsGrid = activeTab.down('knitkit_versions' + contentType + 'gridpanel');
341
+ if (Ext.isEmpty(versionsGrid)) {
342
+ versionsGrid = activeTab.down('knitkit_nonpublishedversionswebsitesectiongridpanel');
343
+ }
344
+
345
+ if (!Ext.isEmpty(versionsGrid)) {
346
+ versionsGrid.getStore().load();
347
+ }
348
+
349
+ }
350
+ }
351
+ else {
352
+ Ext.Msg.alert('Error', 'Error saving contents');
353
+ self.clearWindowStatus();
354
+ }
355
+ },
356
+ failure:function (response) {
357
+ self.clearWindowStatus();
358
+ Ext.Msg.alert('Error', 'Error saving contents');
169
359
  }
170
- }
171
- }]
172
- });
360
+ });
361
+ },
362
+
363
+ viewContent:function (title, content) {
364
+ var ckEditor = Ext.create("Compass.ErpApp.Shared.CKeditor", {
365
+ autoHeight:true,
366
+ value:content,
367
+ ckEditorConfig:{
368
+ toolbar:[
369
+ ['Preview']
370
+ ]
371
+ }
372
+ });
173
373
 
174
- this.workArea.add(item);
175
- }
374
+ var item = Ext.create('Ext.panel.Panel', {
375
+ closable:true,
376
+ layout:'fit',
377
+ title:title,
378
+ split:true,
379
+ items:ckEditor,
380
+ autoDestroy:true
381
+ });
176
382
 
177
- this.workArea.setActiveTab(item);
178
- return false;
179
- },
180
-
181
- saveExcerpt : function(id, content){
182
- var self = this;
183
- this.setWindowStatus('Saving...');
184
- Ext.Ajax.request({
185
- url: '/knitkit/erp_app/desktop/content/save_excerpt',
186
- method: 'POST',
187
- params:{
188
- id:id,
189
- html:content
190
- },
191
- success: function(response) {
192
- var obj = Ext.decode(response.responseText);
193
- if(obj.success){
194
- self.clearWindowStatus();
195
- var activeTab = self.workArea.getActiveTab();
196
- var panel = activeTab.query('knitkit_versionsbloggridpanel');
197
- if(panel.length == 0){
198
- panel = activeTab.query('knitkit_nonpublishedversionswebsitesectiongridpanel');
199
- }
200
- panel[0].getStore().load();
383
+ this.workArea.add(item);
384
+ this.workArea.setActiveTab(item);
385
+ },
386
+
387
+ editContent:function (title, id, content, siteId, contentType, contentGridStore) {
388
+ var self = this;
389
+ var itemId = 'editContent-' + id;
390
+ var item = this.workArea.query('#' + itemId).first();
391
+
392
+ if (Compass.ErpApp.Utility.isBlank(item)) {
393
+ var ckEditor = Ext.create("Compass.ErpApp.Shared.CKeditor", {
394
+ autoHeight:true,
395
+ //value:content,
396
+ ckEditorConfig:{
397
+ extraPlugins:'jwplayer',
398
+ toolbar:self.ckEditorToolbar
399
+ }
400
+ });
401
+
402
+ ckEditor.setValue(content);
403
+
404
+ var items = [
405
+ {
406
+ xtype:'panel',
407
+ layout:'fit',
408
+ split:true,
409
+ region:'center',
410
+ items:ckEditor,
411
+ autoDestroy:true
412
+ }
413
+ ];
414
+
415
+ if (!Compass.ErpApp.Utility.isBlank(siteId)) {
416
+ items.push({
417
+ xtype:'knitkit_versions' + contentType + 'gridpanel',
418
+ contentId:id,
419
+ region:'south',
420
+ height:150,
421
+ collapsible:true,
422
+ centerRegion:self,
423
+ siteId:siteId
424
+ });
425
+ }
426
+ else {
427
+ items.push({
428
+ xtype:'knitkit_nonpublishedversionswebsitesectiongridpanel',
429
+ contentId:id,
430
+ region:'south',
431
+ height:150,
432
+ collapsible:true,
433
+ centerRegion:self
434
+ });
435
+ }
436
+
437
+ item = Ext.create('Ext.panel.Panel', {
438
+ xtype:'panel',
439
+ layout:'border',
440
+ title:title,
441
+ itemId:itemId,
442
+ closable:true,
443
+ items:items,
444
+ save:function (comp) {
445
+ if (currentUser.hasApplicationCapability('knitkit', {
446
+ capability_type_iid:'edit_html',
447
+ resource:'Article'
448
+ })) {
449
+ var content = comp.down('ckeditor').getValue();
450
+ self.saveContent(id, content, contentType, siteId);
451
+ if (contentGridStore) {
452
+ contentGridStore.load();
453
+ }
454
+
455
+ } else {
456
+ currentUser.showInvalidAccess();
457
+ }
458
+ },
459
+ listeners:{
460
+ 'show':function (panel) {
461
+ if (!Compass.ErpApp.Utility.isBlank(siteId)) {
462
+ Ext.getCmp('knitkitWestRegion').selectWebsite(siteId);
463
+ }
464
+ }
465
+ }
466
+ });
467
+
468
+ this.workArea.add(item);
201
469
  }
202
- else{
203
- Ext.Msg.alert('Error', 'Error saving excerpt');
204
- self.clearWindowStatus();
470
+
471
+ this.workArea.setActiveTab(item);
472
+ },
473
+
474
+ showComment:function (comment) {
475
+ var activeTab = this.workArea.getActiveTab();
476
+ var cardPanel = activeTab.query('panel')[0];
477
+ cardPanel.removeAll(true);
478
+ cardPanel.add({
479
+ xtype:'panel',
480
+ html:comment
481
+ });
482
+ cardPanel.getLayout().setActiveItem(0);
483
+ },
484
+
485
+ viewContentComments:function (contentId, title) {
486
+ var self = this;
487
+ var itemId = 'contentComments-' + contentId;
488
+ var item = this.workArea.query('#' + itemId).first();
489
+
490
+ if (Compass.ErpApp.Utility.isBlank(item)) {
491
+ item = Ext.create("Ext.panel.Panel", {
492
+ layout:'border',
493
+ itemId:itemId,
494
+ title:title,
495
+ closable:true,
496
+ items:[
497
+ {
498
+ xtype:'panel',
499
+ layout:'card',
500
+ split:true,
501
+ region:'center',
502
+ items:[],
503
+ autoDestroy:true
504
+ },
505
+ {
506
+ xtype:'knitkit_commentsgridpanel',
507
+ contentId:contentId,
508
+ region:'south',
509
+ height:300,
510
+ collapsible:true,
511
+ centerRegion:self
512
+ }
513
+ ]
514
+ });
515
+ this.workArea.add(item);
205
516
  }
206
- },
207
- failure: function(response) {
208
- self.clearWindowStatus();
209
- Ext.Msg.alert('Error', 'Error saving excerpt');
210
- }
211
- });
212
- },
213
-
214
- editExcerpt : function(title, id, content, siteId, contentGridStore){
215
- var self = this;
216
- var itemId = 'editExcerpt-'+id;
217
- var item = this.workArea.query('#'+itemId).first();
218
-
219
- if(Compass.ErpApp.Utility.isBlank(item)){
220
- var ckEditor = Ext.create("Compass.ErpApp.Shared.CKeditor",{
221
- autoHeight:true,
222
- value:content,
223
- ckEditorConfig:{
224
- extraPlugins:'compasssave,jwplayer', // removed codemirror plugin as it is unstable
225
- toolbar:self.ckEditorToolbar
226
- },
227
- listeners:{
228
- 'save':function(ckEditor, content){
229
- self.saveExcerpt(id, content);
230
- contentGridStore.load();
231
- }
517
+
518
+ this.workArea.setActiveTab(item);
519
+ },
520
+
521
+ viewWebsiteInquiries:function (websiteId, title) {
522
+ var self = this;
523
+ var itemId = 'websiteInqueries-' + websiteId;
524
+ var item = this.workArea.query('#' + itemId).first();
525
+
526
+ if (Compass.ErpApp.Utility.isBlank(item)) {
527
+ item = {
528
+ xtype:'panel',
529
+ layout:'border',
530
+ title:title + " Inquiries",
531
+ itemId:itemId,
532
+ closable:true,
533
+ items:[
534
+ {
535
+ xtype:'panel',
536
+ layout:'card',
537
+ split:true,
538
+ region:'center',
539
+ items:[],
540
+ autoDestroy:true
541
+ },
542
+ {
543
+ xtype:'knitkit_inquiriesgridpanel',
544
+ websiteId:websiteId,
545
+ region:'south',
546
+ height:300,
547
+ collapsible:true,
548
+ centerRegion:self
549
+ }
550
+ ],
551
+ listeners:{
552
+ 'show':function (panel) {
553
+ Ext.getCmp('knitkitWestRegion').selectWebsite(websiteId);
554
+ }
555
+ }
556
+ };
557
+
558
+ this.workArea.add(item);
232
559
  }
233
- });
234
-
235
- var items = [ {
236
- xtype:'panel',
237
- layout:'fit',
238
- split:true,
239
- region:'center',
240
- items:ckEditor,
241
- autoDestroy:true
242
- }];
243
-
244
- if(!Compass.ErpApp.Utility.isBlank(siteId)){
245
- items.push( {
246
- xtype:'knitkit_versionsbloggridpanel',
247
- contentId:id,
248
- region:'south',
249
- height:150,
250
- collapsible:true,
251
- centerRegion:self,
252
- siteId:siteId
253
- });
254
- }
255
- else{
256
- items.push({
257
- xtype:'knitkit_nonpublishedversionswebsitesectiongridpanel',
258
- contentId:id,
259
- region:'south',
260
- height:150,
261
- collapsible:true,
262
- centerRegion:self
263
- });
264
- }
265
-
266
- item = Ext.create("Ext.panel.Panel",{
267
- layout:'border',
268
- title:title,
269
- closable:true,
270
- items:items,
271
- itemId:itemId,
272
- listeners:{
273
- 'show':function(panel){
274
- if(!Compass.ErpApp.Utility.isBlank(siteId)){
275
- Ext.getCmp('knitkitWestRegion').selectWebsite(siteId);
560
+
561
+ this.workArea.setActiveTab(item);
562
+ },
563
+
564
+ insertHtmlIntoActiveCkEditor:function (html) {
565
+ var activeTab = this.workArea.getActiveTab();
566
+ if (Compass.ErpApp.Utility.isBlank(activeTab)) {
567
+ Ext.Msg.alert('Error', 'No editor');
568
+ }
569
+ else {
570
+ if (activeTab.query('ckeditor').length == 0) {
571
+ Ext.Msg.alert('Error', 'No ckeditor found');
572
+ }
573
+ else {
574
+ activeTab.query('ckeditor')[0].insertHtml(html);
276
575
  }
277
- }
278
576
  }
279
- });
577
+ return false;
578
+ },
280
579
 
281
- this.workArea.add(item);
282
- }
283
-
284
- this.workArea.setActiveTab(item);
285
- },
286
-
287
- saveContent : function(id, content, contentType){
288
- var self = this;
289
- this.setWindowStatus('Saving...');
290
- Ext.Ajax.request({
291
- url: '/knitkit/erp_app/desktop/content/update',
292
- method: 'POST',
293
- params:{
294
- id:id,
295
- html:content
296
- },
297
- success: function(response) {
298
- var obj = Ext.decode(response.responseText);
299
- if(obj.success){
300
- self.clearWindowStatus();
301
- if(!Compass.ErpApp.Utility.isBlank(contentType)){
302
- var activeTab = self.workArea.getActiveTab();
303
- var panel = activeTab.query('knitkit_versions'+contentType+'gridpanel');
304
- if(panel.length == 0){
305
- panel = activeTab.query('knitkit_nonpublishedversionswebsitesectiongridpanel');
580
+ replaceHtmlInActiveCkEditor:function (html) {
581
+ var activeTab = this.workArea.getActiveTab();
582
+ if (Compass.ErpApp.Utility.isBlank(activeTab)) {
583
+ Ext.Msg.alert('Error', 'No editor');
584
+ }
585
+ else {
586
+ if (activeTab.query('ckeditor').length == 0) {
587
+ Ext.Msg.alert('Error', 'No ckeditor found');
588
+ }
589
+ else {
590
+ activeTab.query('ckeditor')[0].setValue(html);
306
591
  }
307
- panel[0].getStore().load();
308
- }
309
592
  }
310
- else{
311
- Ext.Msg.alert('Error', 'Error saving contents');
312
- self.clearWindowStatus();
593
+ return false;
594
+ },
595
+
596
+ replaceContentInActiveCodeMirror:function (content) {
597
+ var activeTab = this.workArea.getActiveTab();
598
+ if (Compass.ErpApp.Utility.isBlank(activeTab)) {
599
+ Ext.Msg.alert('Error', 'No editor');
313
600
  }
314
- },
315
- failure: function(response) {
316
- self.clearWindowStatus();
317
- Ext.Msg.alert('Error', 'Error saving contents');
318
- }
319
- });
320
- },
321
-
322
- viewContent : function(title, content){
323
- var ckEditor = Ext.create("Compass.ErpApp.Shared.CKeditor",{
324
- autoHeight:true,
325
- value:content,
326
- ckEditorConfig:{
327
- toolbar:[['Preview']]
328
- }
329
- });
330
-
331
- var item = Ext.create('Ext.panel.Panel',{
332
- closable:true,
333
- layout:'fit',
334
- title:title,
335
- split:true,
336
- items:ckEditor,
337
- autoDestroy:true
338
- });
339
-
340
- this.workArea.add(item);
341
- this.workArea.setActiveTab(item);
342
- },
343
-
344
- editContent : function(title, id, content, siteId, contentType, contentGridStore){
345
- var self = this;
346
- var itemId = 'editContent-'+id;
347
- var item = this.workArea.query('#'+itemId).first();
348
-
349
- if(Compass.ErpApp.Utility.isBlank(item)){
350
- var ckEditor = Ext.create("Compass.ErpApp.Shared.CKeditor",{
351
- autoHeight:true,
352
- //value:content,
353
- ckEditorConfig:{
354
- extraPlugins:'compasssave,jwplayer', // removed codemirror plugin as it is unstable
355
- toolbar:self.ckEditorToolbar
356
- },
357
- listeners:{
358
- 'save':function(ckEditor, content){
359
- if (currentUser.hasApplicationCapability('knitkit', {
360
- capability_type_iid:'edit_html',
361
- resource:'Article'
362
- }))
363
- {
364
- self.saveContent(id, content, contentType);
365
- if (contentGridStore){
366
- contentGridStore.load();
367
- }
368
-
369
- }else{
370
- currentUser.showInvalidAccess();
601
+ else {
602
+ if (activeTab.query('codemirror').length == 0) {
603
+ Ext.Msg.alert('Error', 'No codemirror found.');
604
+ }
605
+ else {
606
+ activeTab.query('codemirror')[0].setValue(content);
371
607
  }
372
- }
373
608
  }
374
- });
375
-
376
- ckEditor.setValue(content);
377
-
378
- var items = [
379
- {
380
- xtype:'panel',
381
- layout:'fit',
382
- split:true,
383
- region:'center',
384
- items:ckEditor,
385
- autoDestroy:true
386
- }
387
- ];
388
-
389
- if(!Compass.ErpApp.Utility.isBlank(siteId)){
390
- items.push({
391
- xtype:'knitkit_versions'+contentType+'gridpanel',
392
- contentId:id,
393
- region:'south',
394
- height:150,
395
- collapsible:true,
396
- centerRegion:self,
397
- siteId:siteId
398
- });
399
- }
400
- else{
401
- items.push({
402
- xtype:'knitkit_nonpublishedversionswebsitesectiongridpanel',
403
- contentId:id,
404
- region:'south',
405
- height:150,
406
- collapsible:true,
407
- centerRegion:self
408
- });
409
- }
410
-
411
- item = Ext.create('Ext.panel.Panel',{
412
- xtype:'panel',
413
- layout:'border',
414
- title:title,
415
- itemId:itemId,
416
- closable:true,
417
- items:items,
418
- listeners:{
419
- 'show':function(panel){
420
- if(!Compass.ErpApp.Utility.isBlank(siteId)){
421
- Ext.getCmp('knitkitWestRegion').selectWebsite(siteId);
609
+ return false;
610
+ },
611
+
612
+ addContentToActiveCodeMirror:function (content) {
613
+ var activeTab = this.workArea.getActiveTab();
614
+ if (Compass.ErpApp.Utility.isBlank(activeTab)) {
615
+ Ext.Msg.alert('Error', 'No editor');
616
+ }
617
+ else {
618
+ if (activeTab.query('codemirror').length == 0) {
619
+ Ext.Msg.alert('Error', 'No codemirror found. Note that a widget can only be added to a Layout.');
620
+ }
621
+ else {
622
+ activeTab.query('codemirror')[0].insertContent(content);
422
623
  }
423
- }
424
624
  }
425
- });
625
+ return false;
626
+ this.workArea.add(item);
426
627
 
427
- this.workArea.add(item);
428
- }
628
+ this.workArea.setActiveTab(item);
629
+ },
429
630
 
430
- this.workArea.setActiveTab(item);
431
- },
432
-
433
- showComment : function(comment){
434
- var activeTab = this.workArea.getActiveTab();
435
- var cardPanel = activeTab.query('panel')[0];
436
- cardPanel.removeAll(true);
437
- cardPanel.add({
438
- xtype:'panel',
439
- html:comment
440
- });
441
- cardPanel.getLayout().setActiveItem(0);
442
- },
443
-
444
- viewContentComments : function(contentId, title){
445
- var self = this;
446
- var itemId = 'contentComments-'+contentId;
447
- var item = this.workArea.query('#'+itemId).first();
448
-
449
- if(Compass.ErpApp.Utility.isBlank(item)){
450
- item = Ext.create("Ext.panel.Panel",{
451
- layout:'border',
452
- itemId:itemId,
453
- title:title,
454
- closable:true,
455
- items:[
456
- {
457
- xtype:'panel',
458
- layout:'card',
459
- split:true,
460
- region:'center',
461
- items:[],
462
- autoDestroy:true
463
- },
464
- {
465
- xtype:'knitkit_commentsgridpanel',
466
- contentId:contentId,
467
- region:'south',
468
- height:300,
469
- collapsible:true,
470
- centerRegion:self
631
+ insertHtmlIntoActiveCkEditorOrCodemirror:function (html) {
632
+ var activeTab = this.workArea.getActiveTab();
633
+ if (Compass.ErpApp.Utility.isBlank(activeTab)) {
634
+ Ext.Msg.alert('Error', 'No editor');
471
635
  }
472
- ]
473
- });
474
- this.workArea.add(item);
475
- }
476
-
477
- this.workArea.setActiveTab(item);
478
- },
479
-
480
- viewWebsiteInquiries : function(websiteId, title){
481
- var self = this;
482
- var itemId = 'websiteInqueries-'+websiteId;
483
- var item = this.workArea.query('#'+itemId).first();
484
-
485
- if(Compass.ErpApp.Utility.isBlank(item)){
486
- item = {
487
- xtype:'panel',
488
- layout:'border',
489
- title:title + " Inquiries",
490
- itemId:itemId,
491
- closable:true,
492
- items:[
493
- {
494
- xtype:'panel',
495
- layout:'card',
496
- split:true,
497
- region:'center',
498
- items:[],
499
- autoDestroy:true
500
- },
501
- {
502
- xtype:'knitkit_inquiriesgridpanel',
503
- websiteId:websiteId,
504
- region:'south',
505
- height:300,
506
- collapsible:true,
507
- centerRegion:self
636
+ else {
637
+ if (activeTab.query('ckeditor').length > 0) {
638
+ activeTab.query('ckeditor')[0].insertHtml(html);
639
+ }
640
+ else if (activeTab.query('codemirror').length > 0) {
641
+ activeTab.query('codemirror')[0].insertContent(html);
642
+ }
643
+ else {
644
+ Ext.Msg.alert('Error', 'No ckeditor or codemirror found');
645
+ }
646
+ }
647
+ return false;
648
+ },
649
+
650
+ insertHtmlIntoActiveCkEditor:function (html) {
651
+ var activeTab = this.workArea.getActiveTab();
652
+ if (Compass.ErpApp.Utility.isBlank(activeTab)) {
653
+ Ext.Msg.alert('Error', 'No editor');
508
654
  }
509
- ],
510
- listeners:{
511
- 'show':function(panel){
512
- Ext.getCmp('knitkitWestRegion').selectWebsite(websiteId);
513
- }
655
+ else {
656
+ if (activeTab.query('ckeditor').length == 0) {
657
+ Ext.Msg.alert('Error', 'No ckeditor found');
658
+ }
659
+ else {
660
+ activeTab.query('ckeditor')[0].insertHtml(html);
661
+ }
514
662
  }
515
- };
663
+ return false;
664
+ },
665
+ saveCurrent:function () {
666
+ var activeTab = this.workArea.getActiveTab();
667
+ if (!Ext.isEmpty(activeTab) && !Ext.isEmpty(activeTab.initialConfig.save)) {
668
+ activeTab.initialConfig.save(activeTab);
669
+ }
670
+ },
516
671
 
517
- this.workArea.add(item);
518
- }
519
-
520
- this.workArea.setActiveTab(item);
521
- },
522
-
523
- insertHtmlIntoActiveCkEditor : function(html){
524
- var activeTab = this.workArea.getActiveTab();
525
- if(Compass.ErpApp.Utility.isBlank(activeTab)){
526
- Ext.Msg.alert('Error', 'No editor');
527
- }
528
- else{
529
- if(activeTab.query('ckeditor').length == 0){
530
- Ext.Msg.alert('Error', 'No ckeditor found');
531
- }
532
- else{
533
- activeTab.query('ckeditor')[0].insertHtml(html);
534
- }
535
- }
536
- return false;
537
- },
538
672
 
539
- replaceHtmlInActiveCkEditor : function(html){
540
- var activeTab = this.workArea.getActiveTab();
541
- if(Compass.ErpApp.Utility.isBlank(activeTab)){
542
- Ext.Msg.alert('Error', 'No editor');
543
- }
544
- else{
545
- if(activeTab.query('ckeditor').length == 0){
546
- Ext.Msg.alert('Error', 'No ckeditor found');
547
- }
548
- else{
549
- activeTab.query('ckeditor')[0].setValue(html);
550
- }
551
- }
552
- return false;
553
- },
673
+ saveAll:function () {
674
+ this.workArea.items.each(function (comp) {
675
+ if (!Ext.isEmpty(comp) && !Ext.isEmpty(comp.initialConfig.save)) {
676
+ comp.initialConfig.save(comp);
677
+ }
678
+ });
679
+ },
680
+
681
+ constructor:function (config) {
682
+ this.workArea = Ext.createWidget('tabpanel', {
683
+ autoDestroy:true,
684
+ region:'center',
685
+ plugins:Ext.create('Ext.ux.TabCloseMenu', {
686
+ extraItemsTail:[
687
+ '-',
688
+ {
689
+ text:'Closable',
690
+ checked:true,
691
+ hideOnClick:true,
692
+ handler:function (item) {
693
+ currentItem.tab.setClosable(item.checked);
694
+ }
695
+ }
696
+ ],
697
+ listeners:{
698
+ aftermenu:function () {
699
+ currentItem = null;
700
+ },
701
+ beforemenu:function (menu, item) {
702
+ var menuitem = menu.child('*[text="Closable"]');
703
+ currentItem = item;
704
+ menuitem.setChecked(item.closable);
705
+ }
706
+ }
707
+ })
708
+ });
554
709
 
555
- replaceContentInActiveCodeMirror : function(content){
556
- var activeTab = this.workArea.getActiveTab();
557
- if(Compass.ErpApp.Utility.isBlank(activeTab)){
558
- Ext.Msg.alert('Error', 'No editor');
559
- }
560
- else{
561
- if(activeTab.query('codemirror').length == 0){
562
- Ext.Msg.alert('Error', 'No codemirror found.');
563
- }
564
- else{
565
- activeTab.query('codemirror')[0].setValue(content);
566
- }
567
- }
568
- return false;
569
- },
710
+ config = Ext.apply({
711
+ id:'knitkitCenterRegion',
712
+ autoDestroy:true,
713
+ layout:'border',
714
+ region:'center',
715
+ //split:true,
716
+ items:[this.workArea]
717
+ }, config);
570
718
 
571
- addContentToActiveCodeMirror : function(content){
572
- var activeTab = this.workArea.getActiveTab();
573
- if(Compass.ErpApp.Utility.isBlank(activeTab)){
574
- Ext.Msg.alert('Error', 'No editor');
575
- }
576
- else{
577
- if(activeTab.query('codemirror').length == 0){
578
- Ext.Msg.alert('Error', 'No codemirror found. Note that a widget can only be added to a Layout.');
579
- }
580
- else{
581
- activeTab.query('codemirror')[0].insertContent(content);
582
- }
719
+ this.callParent([config]);
583
720
  }
584
- return false;
585
- },
586
-
587
- constructor : function(config) {
588
- this.workArea = Ext.createWidget('tabpanel', {
589
- autoDestroy:true,
590
- region:'center',
591
- plugins: Ext.create('Ext.ux.TabCloseMenu', {
592
- extraItemsTail: [
593
- '-',
594
- {
595
- text: 'Closable',
596
- checked: true,
597
- hideOnClick: true,
598
- handler: function (item) {
599
- currentItem.tab.setClosable(item.checked);
600
- }
601
- }
602
- ],
603
- listeners: {
604
- aftermenu: function () {
605
- currentItem = null;
606
- },
607
- beforemenu: function (menu, item) {
608
- var menuitem = menu.child('*[text="Closable"]');
609
- currentItem = item;
610
- menuitem.setChecked(item.closable);
611
- }
612
- }
613
- })
614
- });
615
-
616
- config = Ext.apply({
617
- id:'knitkitCenterRegion',
618
- autoDestroy:true,
619
- layout:'border',
620
- region:'center',
621
- split:true,
622
- items:[this.workArea]
623
- }, config);
624
-
625
- this.callParent([config]);
626
- }
627
721
  });