aboutsummaryrefslogtreecommitdiff
path: root/js/document/models
diff options
context:
space:
mode:
authorValerio Virgillito2012-05-08 17:36:57 -0700
committerValerio Virgillito2012-05-08 17:36:57 -0700
commitf8c467bd268e10d4f07136ca932c6eaffc94bc12 (patch)
tree16c9785629451a461f855cba4b4e36f28e639a8c /js/document/models
parentb425025001c0ef0ea0ea8439d60a133c3fac61b0 (diff)
parentef1daccfad5381badd53b9d045c2687f9b0e090d (diff)
downloadninja-f8c467bd268e10d4f07136ca932c6eaffc94bc12.tar.gz
Merge pull request #204 from joseeight/Document
I/O: Adding Save Functionality
Diffstat (limited to 'js/document/models')
-rwxr-xr-xjs/document/models/base.js102
1 files changed, 86 insertions, 16 deletions
diff --git a/js/document/models/base.js b/js/document/models/base.js
index 5667fb24..2bbbe501 100755
--- a/js/document/models/base.js
+++ b/js/document/models/base.js
@@ -76,39 +76,104 @@ exports.BaseDocumentModel = Montage.create(Component, {
76 //TODO: Add API to allow other browser support 76 //TODO: Add API to allow other browser support
77 browserPreview: { 77 browserPreview: {
78 value: function (browser) { 78 value: function (browser) {
79 79 //Generating URL for document
80 //TODO: Add file save before previewing 80 var url = this.application.ninja.coreIoApi.rootUrl + this.file.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1];
81 81 //TODO: Add logic to prompt user to save (all) before preview
82 //Currently only supporting current browser (Chrome, obviously) 82 this.saveAll(function (result) {
83 switch (browser) { 83 //Currently only supporting current browser (Chrome, obviously)
84 case 'chrome': 84 switch (this.browser) {
85 window.open(this.application.ninja.coreIoApi.rootUrl + this.file.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]); 85 case 'chrome':
86 break; 86 window.open(this.url);
87 default: 87 break;
88 window.open(this.application.ninja.coreIoApi.rootUrl + this.file.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]); 88 default:
89 break; 89 window.open(this.url);
90 } 90 break;
91 }
92 }.bind({browser: browser, url: url}));
91 } 93 }
92 }, 94 },
93 //////////////////////////////////////////////////////////////////// 95 ////////////////////////////////////////////////////////////////////
94 // 96 //
97 getStyleSheets: {
98 value: function () {
99 //
100 var styles = [];
101 //
102 for (var k in this.views.design.iframe.contentWindow.document.styleSheets) {
103 if (this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode && this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode.getAttribute) {
104 if (this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode.getAttribute('data-ninja-template') === null) {
105 styles.push(this.views.design.iframe.contentWindow.document.styleSheets[k]);
106 }
107 }
108 }
109 //
110 return styles;
111 }
112 },
113 ////////////////////////////////////////////////////////////////////
114 //
95 save: { 115 save: {
96 value: function () { 116 value: function (callback) {
97 // 117 //
118 if (this.currentView === this.views.design) {
119 //
120 this.application.ninja.ioMediator.fileSave({
121 mode: 'html',
122 file: this.file,
123 webgl: this.webGlHelper.glData,
124 styles: this.getStyleSheets(),
125 document: this.views.design.iframe.contentWindow.document,
126 head: this.views.design.iframe.contentWindow.document.head,
127 body: this.views.design.iframe.contentWindow.document.body
128 }, callback.bind(this));
129 } else {
130 //TODO: Add logic to save code view data
131 }
132 //
133 if (this.needsSave) {
134 //Save
135 } else {
136 //Ignore command
137 }
98 } 138 }
99 }, 139 },
100 //////////////////////////////////////////////////////////////////// 140 ////////////////////////////////////////////////////////////////////
101 // 141 //
102 saveAs: { 142 saveAll: {
103 value: function () { 143 value: function (callback) {
144 //
145 if (this.currentView === this.views.design) {
146 //
147 this.application.ninja.ioMediator.fileSave({
148 mode: 'html',
149 file: this.file,
150 webgl: this.webGlHelper.glData,
151 css: this.getStyleSheets(),
152 document: this.views.design.iframe.contentWindow.document,
153 head: this.views.design.iframe.contentWindow.document.head,
154 body: this.views.design.iframe.contentWindow.document.body
155 }, callback.bind(this));
156 } else {
157 //TODO: Add logic to save code view data
158 }
104 // 159 //
160 if (this.needsSave) {
161 //Save
162 } else {
163 //Ignore command
164 }
105 } 165 }
106 }, 166 },
107 //////////////////////////////////////////////////////////////////// 167 ////////////////////////////////////////////////////////////////////
108 // 168 //
109 saveAll: { 169 saveAs: {
110 value: function () { 170 value: function () {
111 // 171 //
172 if (this.needsSave) {
173 //Save current file on memory
174 } else {
175 //Copy file from disk
176 }
112 } 177 }
113 }, 178 },
114 //////////////////////////////////////////////////////////////////// 179 ////////////////////////////////////////////////////////////////////
@@ -116,6 +181,11 @@ exports.BaseDocumentModel = Montage.create(Component, {
116 close: { 181 close: {
117 value: function () { 182 value: function () {
118 // 183 //
184 if (this.needsSave) {
185 //Prompt user to save of lose data
186 } else {
187 //Close file
188 }
119 } 189 }
120 } 190 }
121 //////////////////////////////////////////////////////////////////// 191 ////////////////////////////////////////////////////////////////////