diff options
author | Jonathan Duran | 2012-05-31 08:54:48 -0700 |
---|---|---|
committer | Jonathan Duran | 2012-05-31 08:54:48 -0700 |
commit | f297093b5bfa62c9832829751a12f0e556bb5cc0 (patch) | |
tree | 6e04cdf142cb1b36e2197970c9dc2141017a2be7 /js/controllers/document-controller.js | |
parent | 9253e2ce98d748edd8c3929f113a597923960387 (diff) | |
parent | d49c909cff7f0c5e5d0b127ad84a2fefc6677dc6 (diff) | |
download | ninja-f297093b5bfa62c9832829751a12f0e556bb5cc0.tar.gz |
Merge branch 'refs/heads/NINJAmaster' into TimelineUber
Conflicts:
js/panels/Timeline/Layer.reel/Layer.js
js/panels/Timeline/TimelinePanel.reel/TimelinePanel.js
js/panels/properties.reel/properties.js
Signed-off-by: Jonathan Duran <jduran@motorola.com>
Diffstat (limited to 'js/controllers/document-controller.js')
-rwxr-xr-x | js/controllers/document-controller.js | 555 |
1 files changed, 265 insertions, 290 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index c6bf4c6b..2c34eedf 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js | |||
@@ -9,31 +9,18 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
9 | var Montage = require("montage/core/core").Montage, | 9 | var Montage = require("montage/core/core").Montage, |
10 | Component = require("montage/ui/component").Component, | 10 | Component = require("montage/ui/component").Component, |
11 | Uuid = require("montage/core/uuid").Uuid, | 11 | Uuid = require("montage/core/uuid").Uuid, |
12 | HTMLDocument = require("js/document/html-document").HTMLDocument, | 12 | HTMLDocument = require("js/document/document-html").HtmlDocument, |
13 | TextDocument = require("js/document/text-document").TextDocument; | 13 | TextDocument = require("js/document/document-text").TextDocument; |
14 | |||
15 | // New Document Objects | ||
16 | var Document = require("js/document/document-html").HtmlDocument; | ||
17 | //////////////////////////////////////////////////////////////////////// | 14 | //////////////////////////////////////////////////////////////////////// |
18 | // | 15 | // |
19 | var DocumentController = exports.DocumentController = Montage.create(Component, { | 16 | exports.DocumentController = Montage.create(Component, { |
20 | hasTemplate: { | 17 | // |
21 | value: false | 18 | hasTemplate: {value: false}, |
22 | }, | 19 | _documents: {value: []}, |
23 | 20 | //TODO: what is this?!?! | |
24 | webTemplate: { | 21 | _hackInitialStyles: {value: true}, |
25 | value: false | ||
26 | }, | ||
27 | |||
28 | _documents: { | ||
29 | value: [] | ||
30 | }, | ||
31 | |||
32 | _hackRootFlag: { | ||
33 | value: false | ||
34 | }, | ||
35 | |||
36 | _activeDocument: { value: null }, | 22 | _activeDocument: { value: null }, |
23 | //TODO: Are any of these needed? | ||
37 | _iframeCounter: { value: 1, enumerable: false }, | 24 | _iframeCounter: { value: 1, enumerable: false }, |
38 | _iframeHolder: { value: null, enumerable: false }, | 25 | _iframeHolder: { value: null, enumerable: false }, |
39 | _textHolder: { value: null, enumerable: false }, | 26 | _textHolder: { value: null, enumerable: false }, |
@@ -44,21 +31,19 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
44 | return this._activeDocument; | 31 | return this._activeDocument; |
45 | }, | 32 | }, |
46 | set: function(doc) { | 33 | set: function(doc) { |
47 | if(!!this._activeDocument){ this._activeDocument.isActive = false;} | 34 | //if(!!this._activeDocument){ this._activeDocument.isActive = false;} |
35 | |||
48 | this._activeDocument = doc; | 36 | this._activeDocument = doc; |
37 | |||
49 | if(!!this._activeDocument){ | 38 | if(!!this._activeDocument){ |
50 | if(this._documents.indexOf(doc) === -1) this._documents.push(doc); | 39 | if(this._documents.indexOf(doc) === -1) this._documents.push(doc); |
51 | this._activeDocument.isActive = true; | 40 | this._activeDocument.isActive = true; |
52 | |||
53 | if(!!this._activeDocument.editor){ | ||
54 | this._activeDocument.editor.focus(); | ||
55 | } | ||
56 | } | 41 | } |
57 | } | 42 | } |
58 | }, | 43 | }, |
59 | 44 | ||
60 | deserializedFromTemplate: { | 45 | deserializedFromTemplate: { |
61 | value: function() { | 46 | value: function() { //TODO: Add event naming consistency (save, fileOpen and newFile should be consistent, all file events should be executeFile[operation name]) |
62 | this.eventManager.addEventListener("appLoaded", this, false); | 47 | this.eventManager.addEventListener("appLoaded", this, false); |
63 | this.eventManager.addEventListener("executeFileOpen", this, false); | 48 | this.eventManager.addEventListener("executeFileOpen", this, false); |
64 | this.eventManager.addEventListener("executeNewFile", this, false); | 49 | this.eventManager.addEventListener("executeNewFile", this, false); |
@@ -69,37 +54,30 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
69 | this.eventManager.addEventListener("executeFileCloseAll", this, false); | 54 | this.eventManager.addEventListener("executeFileCloseAll", this, false); |
70 | 55 | ||
71 | this.eventManager.addEventListener("styleSheetDirty", this, false); | 56 | this.eventManager.addEventListener("styleSheetDirty", this, false); |
72 | |||
73 | this.eventManager.addEventListener("addComponentFirstDraw", this, false); | ||
74 | |||
75 | // Temporary add listeners for the new stage templates | ||
76 | this.eventManager.addEventListener("executeWebpageOpen", this, false); | ||
77 | this.eventManager.addEventListener("executeNewWebpage", this, false); | ||
78 | } | 57 | } |
79 | }, | 58 | }, |
80 | 59 | ||
81 | handleAddComponentFirstDraw: { | ||
82 | value: function (e) { | ||
83 | //TODO: Add logic to reparse the document for dynamically added styles | ||
84 | //console.log(e); | ||
85 | } | ||
86 | }, | ||
87 | |||
88 | |||
89 | |||
90 | |||
91 | 60 | ||
92 | //////////////////////////////////////////////////////////////////// | 61 | //TODO: Ensure these APIs are not needed |
62 | redirectRequests: { | ||
63 | value: false | ||
64 | }, | ||
65 | //////////////////////////////////////////////////////////////////// | ||
93 | // | 66 | // |
94 | handleWebRequest: { | 67 | handleWebRequest: { |
95 | value: function (request) { | 68 | value: function (request) { |
96 | //TODO: Check if frameId is proper | 69 | //TODO: Check if frameId is proper |
97 | if (this._hackRootFlag && request.parentFrameId !== -1) { | 70 | if (this.redirectRequests && request.parentFrameId !== -1) { |
98 | //TODO: Optimize creating string | 71 | //Checking for proper URL redirect (from different directories) |
99 | //console.log(request); | 72 | if (request.url.indexOf('js/document/templates/banner') !== -1) { |
100 | //console.log(this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1], request.url); | 73 | return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/banner/'))[1]}; |
101 | //return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split('/')[request.url.split('/').length-1]}; | 74 | } else if (request.url.indexOf('js/document/templates/html') !== -1) { |
102 | return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/montage-html/'))[1]}; | 75 | return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/html/'))[1]}; |
76 | } else if (request.url.indexOf('js/document/templates/app') !== -1) { | ||
77 | return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/app/'))[1]}; | ||
78 | } else { | ||
79 | //Error, not a valid folder | ||
80 | } | ||
103 | } | 81 | } |
104 | } | 82 | } |
105 | }, | 83 | }, |
@@ -120,7 +98,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
120 | }, | 98 | }, |
121 | //////////////////////////////////////////////////////////////////// | 99 | //////////////////////////////////////////////////////////////////// |
122 | 100 | ||
123 | |||
124 | 101 | ||
125 | 102 | ||
126 | 103 | ||
@@ -140,47 +117,47 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
140 | } | 117 | } |
141 | }, | 118 | }, |
142 | 119 | ||
143 | handleExecuteWebpageOpen: { | ||
144 | value: function(event) { | ||
145 | this.webTemplate = true; | ||
146 | this.handleExecuteFileOpen(event); | ||
147 | } | ||
148 | }, | ||
149 | |||
150 | handleExecuteNewWebpage: { | ||
151 | value: function(event) { | ||
152 | this.webTemplate = true; | ||
153 | this.handleExecuteNewFile(event); | ||
154 | } | ||
155 | }, | ||
156 | |||
157 | handleExecuteNewFile: { | 120 | handleExecuteNewFile: { |
158 | value: function(event) { | 121 | value: function(event) { |
159 | var newFileSettings = event._event.settings || {}; | 122 | var newFileSettings = event._event.settings || {}; |
160 | if (this.application.ninja.coreIoApi.cloudAvailable()) { | 123 | if (this.application.ninja.coreIoApi.cloudAvailable()) { |
161 | newFileSettings.callback = this.createNewFile.bind(this); | 124 | newFileSettings.callback = this.createNewFile.bind(this); |
162 | this.application.ninja.newFileController.showNewFileDialog(newFileSettings); | 125 | this.application.ninja.newFileController.showNewFileDialog(newFileSettings); |
163 | } | ||
164 | } | 126 | } |
127 | } | ||
165 | }, | 128 | }, |
166 | //////////////////////////////////////////////////////////////////// | 129 | //////////////////////////////////////////////////////////////////// |
167 | //TODO: Check for appropiate structures | 130 | // |
168 | handleExecuteSave: { | 131 | handleExecuteSave: { |
169 | value: function(event) { | 132 | value: function(event) { |
170 | if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ | 133 | // |
171 | //Text and HTML document classes should return the same save object for fileSave | 134 | if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ |
172 | this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this)); | 135 | //Currently we don't need a callback handler |
173 | } | 136 | //this.activeDocument.model.save(this.saveExecuted.bind(this)); |
137 | this.activeDocument.model.save(); | ||
138 | } else { | ||
139 | //Error: cloud not available and/or no active document | ||
140 | } | ||
174 | } | 141 | } |
175 | }, | 142 | }, |
176 | //////////////////////////////////////////////////////////////////// | 143 | //////////////////////////////////////////////////////////////////// |
144 | // | ||
145 | saveExecuted: { | ||
146 | value: function (value) { | ||
147 | //File saved, any callbacks or events should go here (must be added in handleExecuteSave passed as callback) | ||
148 | } | ||
149 | }, | ||
150 | //////////////////////////////////////////////////////////////////// | ||
177 | //TODO: Check for appropiate structures | 151 | //TODO: Check for appropiate structures |
178 | handleExecuteSaveAll: { | 152 | handleExecuteSaveAll: { |
179 | value: function(event) { | 153 | value: function(event) { |
180 | if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ | 154 | // |
181 |