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.js127
1 files changed, 113 insertions, 14 deletions
diff --git a/js/document/models/base.js b/js/document/models/base.js
index 746922ad..5f2a5893 100755
--- a/js/document/models/base.js
+++ b/js/document/models/base.js
@@ -62,55 +62,154 @@ exports.BaseDocumentModel = Montage.create(Component, {
62 }, 62 },
63 //////////////////////////////////////////////////////////////////// 63 ////////////////////////////////////////////////////////////////////
64 // 64 //
65 fileTemplate: {
66 value: null
67 },
68 ////////////////////////////////////////////////////////////////////
69 //
70 parentContainer: {
71 value: null
72 },
73 ////////////////////////////////////////////////////////////////////
74 //
65 views: { 75 views: {
66 value: null 76 value: null
67 }, 77 },
68 //////////////////////////////////////////////////////////////////// 78 ////////////////////////////////////////////////////////////////////
69 // 79 //
70 switchViewTo: { 80 switchViewTo: {
71 value: function () { 81 value: function (view) {
72 // 82 //
73 } 83 }
74 }, 84 },
75 //////////////////////////////////////////////////////////////////// 85 ////////////////////////////////////////////////////////////////////
76 // 86 //TODO: Add API to allow other browser support
77 browserPreview: { 87 browserPreview: {
78 value: function (browser) { 88 value: function (browser) {
79 // 89 //Generating URL for document
80 switch (browser) { 90 var url = this.application.ninja.coreIoApi.rootUrl + this.file.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1];
81 case 'chrome': 91 //TODO: Add logic to prompt user to save (all) before preview
82 break; 92 this.saveAll(function (result) {
83 default: 93 //Currently only supporting current browser (Chrome, obviously)
84 break; 94 switch (this.browser) {
85 } 95 case 'chrome':
96 window.open(this.url);
97 break;
98 default:
99 window.open(this.url);
100 break;
101 }
102 }.bind({browser: browser, url: url}));
86 } 103 }
87 }, 104 },
88 //////////////////////////////////////////////////////////////////// 105 ////////////////////////////////////////////////////////////////////
89 // 106 //
107 getStyleSheets: {
108 value: function () {
109 //
110 var styles = [];
111 //
112 for (var k in this.views.design.iframe.contentWindow.document.styleSheets) {
113 if (this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode && this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode.getAttribute) {
114 if (this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode.getAttribute('data-ninja-template') === null) {
115 styles.push(this.views.design.iframe.contentWindow.document.styleSheets[k]);
116 }
117 }
118 }
119 //
120 return styles;
121 }
122 },
123 ////////////////////////////////////////////////////////////////////
124 //
90 save: { 125 save: {
91 value: function () { 126 value: function (callback) {
127 //
128 if (this.needsSave) {
129 //Save
130 } else {
131 //Ignore command
132 }
92 // 133 //
134 if (this.currentView === this.views.design) {
135 //
136 this.application.ninja.ioMediator.fileSave({
137 mode: 'html',
138 file: this.file,
139 webgl: this.webGlHelper.glData,
140 styles: this.getStyleSheets(),
141 template: this.fileTemplate,
142 document: this.views.design.iframe.contentWindow.document,
143 head: this.views.design.iframe.contentWindow.document.head,
144 body: this.views.design.iframe.contentWindow.document.body
145 }, callback.bind(this));
146 } else {
147 //TODO: Add logic to save code view data
148 }
93 } 149 }
94 }, 150 },
95 //////////////////////////////////////////////////////////////////// 151 ////////////////////////////////////////////////////////////////////
96 // 152 //
97 saveAs: { 153 saveAll: {
98 value: function () { 154 value: function (callback) {
155 //
156 if (this.needsSave) {
157 //Save
158 } else {
159 //Ignore command
160 }
99 // 161 //
162 if (this.currentView === this.views.design) {
163 //
164 this.application.ninja.ioMediator.fileSave({
165 mode: 'html',
166 file: this.file,
167 webgl: this.webGlHelper.glData,
168 css: this.getStyleSheets(),
169 template: this.fileTemplate,
170 document: this.views.design.iframe.contentWindow.document,
171 head: this.views.design.iframe.contentWindow.document.head,
172 body: this.views.design.iframe.contentWindow.document.body
173 }, callback.bind(this));
174 } else {
175 //TODO: Add logic to save code view data
176 }
177
100 } 178 }
101 }, 179 },
102 //////////////////////////////////////////////////////////////////// 180 ////////////////////////////////////////////////////////////////////
103 // 181 //
104 saveAll: { 182 saveAs: {
105 value: function () { 183 value: function () {
106 // 184 //
185 if (this.needsSave) {
186 //Save current file on memory
187 } else {
188 //Copy file from disk
189 }
107 } 190 }
108 }, 191 },
109 //////////////////////////////////////////////////////////////////// 192 ////////////////////////////////////////////////////////////////////
110 // 193 //
111 close: { 194 close: {
112 value: function () { 195 value: function (view, callback) {
196 //Outcome of close (pending on save logic)
197 var success;
198 //
199 if (this.needsSave) {
200 //Prompt user to save of lose data
201 } else {
202 //Close file
203 success = true;
204 }
205 //
206 if (this.views.design && (!view || view === 'design')) {
207 //
208 this.parentContainer.removeChild(this.views.design.iframe);
209 this.views.design = null;
210 }
113 // 211 //
212 if (callback) callback(success);
114 } 213 }
115 } 214 }
116 //////////////////////////////////////////////////////////////////// 215 ////////////////////////////////////////////////////////////////////