aboutsummaryrefslogtreecommitdiff
path: root/js/document/models/base.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/document/models/base.js')
-rwxr-xr-xjs/document/models/base.js198
1 files changed, 188 insertions, 10 deletions
diff --git a/js/document/models/base.js b/js/document/models/base.js
index f237e793..033e16f6 100755
--- a/js/document/models/base.js
+++ b/js/document/models/base.js
@@ -6,42 +6,220 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
6 6
7//////////////////////////////////////////////////////////////////////// 7////////////////////////////////////////////////////////////////////////
8// 8//
9var Montage = require("montage/core/core").Montage; 9var Montage = require("montage/core/core").Montage,
10 Component = require("montage/ui/component").Component;
10//////////////////////////////////////////////////////////////////////// 11////////////////////////////////////////////////////////////////////////
11// 12//
12exports.BaseDocumentModel = Montage.create(Montage, { 13exports.BaseDocumentModel = Montage.create(Component, {
13 //////////////////////////////////////////////////////////////////// 14 ////////////////////////////////////////////////////////////////////
14 // 15 //
15 hasTemplate: { 16 hasTemplate: {
16 enumerable: false,
17 value: false 17 value: false
18 }, 18 },
19 //////////////////////////////////////////////////////////////////// 19 ////////////////////////////////////////////////////////////////////
20 // 20 //
21 file: { 21 _file: {
22 value: null 22 value: null
23 }, 23 },
24 24 ////////////////////////////////////////////////////////////////////
25 _name: { 25 //
26 value: null 26 file: {
27 get: function() {return this._file;},
28 set: function(value) {this._file = value;}
27 }, 29 },
28 30 ////////////////////////////////////////////////////////////////////
31 //
29 _isActive: { 32 _isActive: {
30 value: null 33 value: null
31 }, 34 },
32 35 ////////////////////////////////////////////////////////////////////
36 //
37 isActive: {
38 get: function() {return this._isActive;},
39 set: function(value) {this._isActive = value;}
40 },
41 ////////////////////////////////////////////////////////////////////
42 //
33 _needsSave: { 43 _needsSave: {
34 value: null 44 value: null
35 }, 45 },
36 //////////////////////////////////////////////////////////////////// 46 ////////////////////////////////////////////////////////////////////
37 // 47 //
38 njdata: { 48 needsSave: {
49 get: function() {return this._needsSave;},
50 set: function(value) {this._needsSave = value;}
51 },
52 ////////////////////////////////////////////////////////////////////
53 //
54 _currentView: {
55 value: null
56 },
57 ////////////////////////////////////////////////////////////////////
58 //
59 currentView: {
60 get: function() {return this._currentView;},
61 set: function(value) {this._currentView = value;}
62 },
63 ////////////////////////////////////////////////////////////////////
64 //
65 fileTemplate: {
66 value: null
67 },
68 ////////////////////////////////////////////////////////////////////
69 //
70 parentContainer: {
39 value: null 71 value: null
40 }, 72 },
41 //////////////////////////////////////////////////////////////////// 73 ////////////////////////////////////////////////////////////////////
42 // 74 //
43 views: { 75 views: {
44 value: null 76 value: null
77 },
78 ////////////////////////////////////////////////////////////////////
79 //
80 switchViewTo: {
81 value: function (view) {
82 //
83 }
84 },
85 ////////////////////////////////////////////////////////////////////
86 //TODO: Add API to allow other browser support
87 browserPreview: {
88 value: function (browser) {
89 //Generating URL for document
90 var url = this.application.ninja.coreIoApi.rootUrl + this.file.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1];
91 //TODO: Add logic to prompt user to save (all) before preview
92 this.saveAll(function (result) {
93 //Currently only supporting current browser (Chrome, obviously)
94 switch (this.browser) {
95 case 'chrome':
96 if (this.template && (this.template.type === 'banner' || this.template.type === 'animation')) {
97 window.open('/js/document/templates/preview/banner.html?width='+this.template.size.width+'&height='+this.template.size.height+'&url='+this.url);
98 } else {
99 window.open(this.url);
100 }
101 break;
102 default:
103 if (this.template.type === 'banner' || this.template.type === 'animation') {
104 window.open('/js/document/templates/preview/banner.html?width='+this.template.size.width+'&height='+this.template.size.height+'&url='+this.url);
105 } else {
106 window.open(this.url);
107 }
108 break;
109 }
110 }.bind({browser: browser, url: url, template: this.fileTemplate}));
111 }
112 },
113 ////////////////////////////////////////////////////////////////////
114 //
115 getStyleSheets: {
116 value: function () {
117 //
118 var styles = [];
119 //
120 for (var k in this.views.design.iframe.contentWindow.document.styleSheets) {
121 if (this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode && this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode.getAttribute) {
122 if (this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode.getAttribute('data-ninja-template') === null) {
123 styles.push(this.views.design.iframe.contentWindow.document.styleSheets[k]);
124 }
125 }
126 }
127 //
128 return styles;
129 }
130 },
131 ////////////////////////////////////////////////////////////////////
132 //
133 save: {
134 value: function (callback) {
135 //
136 if (this.needsSave) {
137 //Save
138 } else {
139 //Ignore command
140 }
141 //
142 if (this.currentView === this.views.design) {
143 //
144 this.application.ninja.ioMediator.fileSave({
145 mode: 'html',
146 file: this.file,
147 webgl: this.webGlHelper.glData,
148 styles: this.getStyleSheets(),
149 template: this.fileTemplate,
150 document: this.views.design.iframe.contentWindow.document,
151 head: this.views.design.iframe.contentWindow.document.head,
152 body: this.views.design.iframe.contentWindow.document.body
153 }, callback.bind(this));
154 } else {
155 //TODO: Add logic to save code view data
156 }
157 }
158 },
159 ////////////////////////////////////////////////////////////////////
160 //
161 saveAll: {
162 value: function (callback) {
163 //
164 if (this.needsSave) {
165 //Save
166 } else {
167 //Ignore command
168 }
169 //
170 if (this.currentView === this.views.design) {
171 //
172 this.application.ninja.ioMediator.fileSave({
173 mode: 'html',
174 file: this.file,
175 webgl: this.webGlHelper.glData,
176 css: this.getStyleSheets(),
177 template: this.fileTemplate,
178 document: this.views.design.iframe.contentWindow.document,
179 head: this.views.design.iframe.contentWindow.document.head,
180 body: this.views.design.iframe.contentWindow.document.body
181 }, callback.bind(this));
182 } else {
183 //TODO: Add logic to save code view data
184 }
185
186 }
187 },
188 ////////////////////////////////////////////////////////////////////
189 //
190 saveAs: {
191 value: function () {
192 //
193 if (this.needsSave) {
194 //Save current file on memory
195 } else {
196 //Copy file from disk
197 }
198 }
199 },
200 ////////////////////////////////////////////////////////////////////
201 //
202 close: {
203 value: function (view, callback) {
204 //Outcome of close (pending on save logic)
205 var success;
206 //
207 if (this.needsSave) {
208 //Prompt user to save of lose data
209 } else {
210 //Close file
211 success = true;
212 }
213 //
214 if (this.views.design && (!view || view === 'design')) {
215 //
216 this.parentContainer.removeChild(this.views.design.iframe);
217 this.views.design.pauseAndStopVideos();
218 this.views.design = null;
219 }