aboutsummaryrefslogtreecommitdiff
path: root/js/io/ui/new-file-dialog/new-file-workflow-controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/io/ui/new-file-dialog/new-file-workflow-controller.js')
-rwxr-xr-xjs/io/ui/new-file-dialog/new-file-workflow-controller.js139
1 files changed, 139 insertions, 0 deletions
diff --git a/js/io/ui/new-file-dialog/new-file-workflow-controller.js b/js/io/ui/new-file-dialog/new-file-workflow-controller.js
new file mode 100755
index 00000000..16075ecf
--- /dev/null
+++ b/js/io/ui/new-file-dialog/new-file-workflow-controller.js
@@ -0,0 +1,139 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7var Montage = require("montage/core/core").Montage,
8 Popup = require("montage/ui/popup/popup.reel").Popup,
9 newFileOptionsNavigatorModule = require("js/io/ui/new-file-dialog/new-file-options-navigator.reel"),
10 newFileWorkflowModelModule = require("js/io/ui/new-file-dialog/new-file-workflow-model").NewFileWorkflowModel;
11 saveAsModule = require("js/io/ui/save-as-dialog.reel");
12
13//singleton
14var NewFileWorkflowController = exports.NewFileWorkflowController = Montage.create(require("montage/ui/component").Component, {
15 /**
16 * Register a listener for showPicker event
17 */
18 deserializedFromTemplate:{
19 writable:false,
20 enumerable:true,
21 value:function(){
22 var that = this;
23
24 this.eventManager.addEventListener("saveAs", function(evt){
25 var data = evt._event.data || {};//data will contain the current file name, directory location and callback
26 that.showSaveAsDialog(data);
27 }, false);
28 }
29 },
30
31 model:{
32 writable: true,
33 enumerable:true,
34 value: null
35 },
36
37 showNewFileDialog:{
38 writable:false,
39 enumerable:true,
40 value:function(data){
41 this.model = newFileWorkflowModelModule;
42
43 //read file descriptor to populate model
44 this.model.projectTypeData = this.loadDescriptor("js/io/templates/descriptor.json");
45
46 //get default project type
47 this.model.defaultProjectType = "files/html.txt";
48 this.model.callback = data.callback || null;
49 this.model.callbackScope = data.callbackScope || null;
50
51 //populate the last opened folder first, if none then populate default root
52 var sessionStorage = window.sessionStorage;
53 var lastSelectedProjectType = sessionStorage.getItem("lastSelectedProjectType");
54
55 if(!!lastSelectedProjectType){
56 this.model.defaultProjectType = lastSelectedProjectType;
57 }
58
59 //render modal dialog
60 var newFileNavContent = document.createElement("div");
61 newFileNavContent.id = "newFileDialog";
62
63 //elements needs to be on DOM to be drawn
64 document.getElementById('modalContainer').appendChild(newFileNavContent);
65
66 var newFileOptionsNav = newFileOptionsNavigatorModule.NewFileOptionsNavigator.create();
67 newFileOptionsNav.newFileModel = this.model;
68 newFileOptionsNav.element = newFileNavContent;
69
70 //remove after rendering and add in modal dialog
71 document.getElementById('modalContainer').removeChild(newFileNavContent);
72
73 var popup = Popup.create();
74 popup.content = newFileOptionsNav;
75 popup.modal = true;
76 popup.type = "newFileDialog";
77 popup.show();
78
79 newFileOptionsNav.popup = popup;//handle to be used for hiding the popup
80
81 }
82 },
83
84 showSaveAsDialog:{
85 writable:false,
86 enumerable:true,
87 value:function(data){
88 var fileName = data.fileName || "filename.txt";
89 var folderUri = data.folderUri || "/Documents";
90
91 //render modal dialog
92 var saveAsDialogContainer = document.createElement("div");
93 saveAsDialogContainer.id = "saveAsDialog";
94
95 //elements needs to be on DOM to be drawn
96 document.getElementById('modalContainer').appendChild(saveAsDialogContainer);
97
98 var saveAsDialog = saveAsModule.SaveAsDialog.create();
99 saveAsDialog.fileName = fileName;
100 saveAsDialog.folderUri = folderUri;
101 saveAsDialog.callback = data.callback;
102 saveAsDialog.callbackScope = data.callbackScope;
103 saveAsDialog.element = saveAsDialogContainer;
104
105 //remove after rendering and add in modal dialog
106 document.getElementById('modalContainer').removeChild(saveAsDialogContainer);
107
108 var popup = Popup.create();
109 popup.content = saveAsDialog;
110 popup.modal = true;
111 popup.type = "saveAsDialog";
112 popup.show();
113
114 saveAsDialog.popup = popup;//handle to be used for hiding the popup
115 }
116 },
117
118 loadDescriptor:{
119 value: function(descriptorPath){
120 var content = null, descriptorObj=null;
121 var xhr = new XMLHttpRequest();
122 xhr.open("GET", descriptorPath, false);
123 xhr.send();
124 if (xhr.readyState === 4) {
125 if(xhr.status == 200) {
126 content = xhr.responseText;
127 }
128 }
129 if(!!content && (content.length > 0)){
130 try{
131 descriptorObj = JSON.parse(content);
132 }catch(e){
133 console.log(e,stack);
134 }
135 }
136 return descriptorObj;
137 }
138 }
139}); \ No newline at end of file