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.js99
1 files changed, 69 insertions, 30 deletions
diff --git a/js/document/models/base.js b/js/document/models/base.js
index 76a5e62b..5fa06259 100755
--- a/js/document/models/base.js
+++ b/js/document/models/base.js
@@ -65,14 +65,11 @@ exports.BaseDocumentModel = Montage.create(Component, {
65 _selection: { 65 _selection: {
66 value: [] 66 value: []
67 }, 67 },
68 68 ////////////////////////////////////////////////////////////////////
69 //
69 selection: { 70 selection: {
70 get: function() { 71 get: function() {return this._selection;},
71 return this._selection; 72 set: function(value) {this._selection = value;}
72 },
73 set: function(value) {
74 this._selection = value;
75 }
76 }, 73 },
77 //////////////////////////////////////////////////////////////////// 74 ////////////////////////////////////////////////////////////////////
78 // 75 //
@@ -91,6 +88,11 @@ exports.BaseDocumentModel = Montage.create(Component, {
91 }, 88 },
92 //////////////////////////////////////////////////////////////////// 89 ////////////////////////////////////////////////////////////////////
93 // 90 //
91 libs: {
92 value: null
93 },
94 ////////////////////////////////////////////////////////////////////
95 //
94 switchViewTo: { 96 switchViewTo: {
95 value: function (view) { 97 value: function (view) {
96 // 98 //
@@ -99,11 +101,20 @@ exports.BaseDocumentModel = Montage.create(Component, {
99 //////////////////////////////////////////////////////////////////// 101 ////////////////////////////////////////////////////////////////////
100 //TODO: Add API to allow other browser support 102 //TODO: Add API to allow other browser support
101 browserPreview: { 103 browserPreview: {
102 value: function (browser) { 104 value: function (browser, screen, context) {
105 //Making call to show feedback screen
106 if (screen) screen.show(context);
103 //Generating URL for document 107 //Generating URL for document
104 var url = this.application.ninja.coreIoApi.rootUrl + this.file.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]; 108 var url = this.application.ninja.coreIoApi.rootUrl + this.file.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1];
105 //TODO: Add logic to prompt user to save (all) before preview 109 //TODO: Add logic to prompt user to save (all) before preview
106 this.saveAll(function (result) { 110 this.saveAll(null,function (success) {
111 //Making call to show feedback screen
112 if (screen) screen.hide(context);
113 //TODO: Add error handling logic
114 if (!success) {
115 console.log('Error!');
116 return;
117 }
107 //Currently only supporting current browser (Chrome, obviously) 118 //Currently only supporting current browser (Chrome, obviously)
108 switch (this.browser) { 119 switch (this.browser) {
109 case 'chrome': 120 case 'chrome':
@@ -125,28 +136,30 @@ exports.BaseDocumentModel = Montage.create(Component, {
125 } 136 }
126 }, 137 },
127 //////////////////////////////////////////////////////////////////// 138 ////////////////////////////////////////////////////////////////////
128 // 139 //Gets all stylesheets in document
129 getStyleSheets: { 140 getStyleSheets: {
130 value: function () { 141 value: function () {
131 // 142 //Array to store styles (style and link tags)
132 var styles = []; 143 var styles = [];
133 // 144 //Looping through document sytles
134 for (var k in this.views.design.iframe.contentWindow.document.styleSheets) { 145 for (var k in this.views.design.iframe.contentWindow.document.styleSheets) {
146 //Check for styles to has proper propeties
135 if (this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode && this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode.getAttribute) { 147 if (this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode && this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode.getAttribute) {
148 //Check for ninja-template styles, if so, exclude
136 if (this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode.getAttribute('data-ninja-template') === null) { 149 if (this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode.getAttribute('data-ninja-template') === null) {
137 styles.push(this.views.design.iframe.contentWindow.document.styleSheets[k]); 150 styles.push(this.views.design.iframe.contentWindow.document.styleSheets[k]);
138 } 151 }
139 } 152 }
140 } 153 }
141 // 154 //Returning filtered results
142 return styles; 155 return styles;
143 } 156 }
144 }, 157 },
145 //////////////////////////////////////////////////////////////////// 158 ////////////////////////////////////////////////////////////////////
146 // 159 //
147 save: { 160 save: {
148 value: function (callback) { 161 value: function (callback, libCopyCallback) {
149 // 162 //TODO: Implement on demand logic
150 if (this.needsSave) { 163 if (this.needsSave) {
151 //Save 164 //Save
152 } else { 165 } else {
@@ -155,8 +168,9 @@ exports.BaseDocumentModel = Montage.create(Component, {
155 // 168 //
156 if (this.currentView === this.views.design) { 169 if (this.currentView === this.views.design) {
157 // 170 //
158 this.application.ninja.ioMediator.fileSave({ 171 var save = this.application.ninja.ioMediator.fileSave({
159 mode: 'html', 172 mode: 'html',
173 libs: this.libs,
160 file: this.file, 174 file: this.file,
161 webgl: this.webGlHelper.glData, 175 webgl: this.webGlHelper.glData,
162 styles: this.getStyleSheets(), 176 styles: this.getStyleSheets(),
@@ -165,7 +179,18 @@ exports.BaseDocumentModel = Montage.create(Component, {
165 head: this.views.design.iframe.contentWindow.document.head, 179 head: this.views.design.iframe.contentWindow.document.head,
166 body: this.views.design.iframe.contentWindow.document.body, 180 body: this.views.design.iframe.contentWindow.document.body,
167 mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator 181 mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator
168 }, this.handleSaved.bind({callback: callback, model: this})); 182 }, this.handleSaved.bind({callback: callback, model: this}), libCopyCallback);
183 //TODO: Improve detection during save routine
184 if (save) {
185 if (save.montageId) {
186 this.libs.montageId = save.montageId;
187 this.libs.montage = true;
188 }
189 if (save.canvasId) {
190 this.libs.canvasId = save.canvasId;
191 this.libs.canvas = true;
192 }
193 }
169 } else { 194 } else {
170 //TODO: Add logic to save code view data 195 //TODO: Add logic to save code view data
171 } 196 }
@@ -174,8 +199,8 @@ exports.BaseDocumentModel = Montage.create(Component, {
174 //////////////////////////////////////////////////////////////////// 199 ////////////////////////////////////////////////////////////////////
175 // 200 //
176 saveAll: { 201 saveAll: {
177 value: function (callback) { 202 value: function (callback, libCopyCallback) {
178 // 203 //TODO: Implement on demand logic
179 if (this.needsSave) { 204 if (this.needsSave) {
180 //Save 205 //Save
181 } else { 206 } else {
@@ -184,8 +209,9 @@ exports.BaseDocumentModel = Montage.create(Component, {
184 // 209 //
185 if (this.currentView === this.views.design) { 210 if (this.currentView === this.views.design) {
186 // 211 //
187 this.application.ninja.ioMediator.fileSave({ 212 var save = this.application.ninja.ioMediator.fileSave({
188 mode: 'html', 213 mode: 'html',
214 libs: this.libs,
189 file: this.file, 215 file: this.file,
190 webgl: this.webGlHelper.glData, 216 webgl: this.webGlHelper.glData,
191 css: this.getStyleSheets(), 217 css: this.getStyleSheets(),
@@ -194,7 +220,18 @@ exports.BaseDocumentModel = Montage.create(Component, {
194 head: this.views.design.iframe.contentWindow.document.head, 220 head: this.views.design.iframe.contentWindow.document.head,
195 body: this.views.design.iframe.contentWindow.document.body, 221 body: this.views.design.iframe.contentWindow.document.body,
196 mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator 222 mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator
197 }, this.handleSaved.bind({callback: callback, model: this})); 223 }, this.handleSaved.bind({callback: callback, model: this}), libCopyCallback);
224 //TODO: Improve detection during save routine
225 if (save) {
226 if (save.montageId) {
227 this.libs.montageId = save.montageId;
228 this.libs.montage = true;
229 }
230 if (save.canvasId) {
231 this.libs.canvasId = save.canvasId;
232 this.libs.canvas = true;
233 }
234 }
198 } else { 235 } else {
199 //TODO: Add logic to save code view data 236 //TODO: Add logic to save code view data
200 } 237 }
@@ -205,47 +242,49 @@ exports.BaseDocumentModel = Montage.create(Component, {
205 // 242 //
206 saveAs: { 243 saveAs: {
207 value: function (callback) { 244 value: function (callback) {
208 // 245 //TODO: Implement on demand logic
209 if (this.needsSave) { 246 if (this.needsSave) {
210 //Save current file on memory 247 //Save current file on memory
211 } else { 248 } else {
212 //Copy file from disk 249 //Copy file from disk
213 } 250 }
251 //TODO: Add functionality
214 } 252 }
215 }, 253 },
216 //////////////////////////////////////////////////////////////////// 254 ////////////////////////////////////////////////////////////////////
217 // 255 //
218 handleSaved: { 256 handleSaved: {
219 value: function (result) { 257 value: function (result) {
220 // 258 //Checking for success code in save
221 if (result.status === 204) { 259 if (result.status === 204) {
260 //Clearing flag with successful save
222 this.model.needsSave = false; 261 this.model.needsSave = false;
223 } 262 }
224 // 263 //Making callback call if specifed with results of operation
225 if (this.callback) this.callback(result); 264 if (this.callback) this.callback(result);