aboutsummaryrefslogtreecommitdiff
path: root/js/document/models/base.js
diff options
context:
space:
mode:
authorAnanya Sen2012-05-31 10:13:40 -0700
committerAnanya Sen2012-05-31 10:13:40 -0700
commit286457b4f23974277274ba388afd283e8aa085cb (patch)
treec21bf791e7c4f572d12f97987ea6b89e74da67fe /js/document/models/base.js
parent4d9b481c58090e8f1fc7b0e9d73a81b0f49cccc8 (diff)
parentd49c909cff7f0c5e5d0b127ad84a2fefc6677dc6 (diff)
downloadninja-286457b4f23974277274ba388afd283e8aa085cb.tar.gz
Merge branch 'refs/heads/ninja-internal-master' into cut-copy-paste
Conflicts: js/controllers/styles-controller.js Signed-off-by: Ananya Sen <Ananya.Sen@motorola.com>
Diffstat (limited to 'js/document/models/base.js')
-rwxr-xr-xjs/document/models/base.js214
1 files changed, 203 insertions, 11 deletions
diff --git a/js/document/models/base.js b/js/document/models/base.js
index f237e793..6d9d2e89 100755
--- a/js/document/models/base.js
+++ b/js/document/models/base.js
@@ -6,42 +6,234 @@ 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: true
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 && (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 mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator
154 }, this.handleSaved.bind({callback: callback, model: this}));
155 } else {
156 //TODO: Add logic to save code view data
157 }
158 }
159 },
160 ////////////////////////////////////////////////////////////////////
161 //
162 saveAll: {
163 value: function (callback) {
164 //
165 if (this.needsSave) {
166 //Save
167 } else {
168 //Ignore command
169 }
170 //
171 if (this.currentView === this.views.design) {
172 //
173 this.application.ninja.ioMediator.fileSave({
174 mode: 'html',
175 file: this.file,
176 webgl: this.webGlHelper.glData,
177 css: this.getStyleSheets(),
178 template: this.fileTemplate,
179 document: this.views.design.iframe.contentWindow.document,
180 head: this.views.design.iframe.contentWindow.document.head,
181 body: this.views.design.iframe.contentWindow.document.body,
182 mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator
183 }, this.handleSaved.bind({callback: callback, model: this}));
184 } else {
185 //TODO: Add logic to save code view data
186 }
187
188 }
189 },
190 ////////////////////////////////////////////////////////////////////
191 //
192 saveAs: {
193 value: function (callback) {
194 //
195 if (this.needsSave) {
196 //Save current file on memory
197 } else {
198 //Copy file from disk
199 }
200 }
201 },
202 ////////////////////////////////////////////////////////////////////
203 //
204 handleSaved: {
205 value: function (result) {
206 //
207 if (result.status === 204) {
208 this.model.needsSave = false;
209 }
210 //
211 if (this.callback) this.callback(result);
212