diff options
Diffstat (limited to 'js/io/ui/new-file-dialog/new-file-workflow-controller.js')
-rwxr-xr-x | js/io/ui/new-file-dialog/new-file-workflow-controller.js | 116 |
1 files changed, 116 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..cfe7db16 --- /dev/null +++ b/js/io/ui/new-file-dialog/new-file-workflow-controller.js | |||
@@ -0,0 +1,116 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No 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 | |||
7 | var 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"); | ||
11 | saveAsModule = require("js/io/ui/save-as-dialog.reel"); | ||
12 | |||
13 | //singleton | ||
14 | var 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 | this.eventManager.addEventListener("executeNewFile", function(evt){ | ||
24 | var data = evt._event.data || {};//data will contain callback | ||
25 | that.showNewFileDialog(data); | ||
26 | }, false); | ||
27 | |||
28 | this.eventManager.addEventListener("saveAs", function(evt){ | ||
29 | var data = evt._event.data || {};//data will contain the current file name, directory location and callback | ||
30 | that.showSaveAsDialog(data); | ||
31 | }, false); | ||
32 | } | ||
33 | }, | ||
34 | |||
35 | model:{ | ||
36 | writable: true, | ||
37 | enumerable:true, | ||
38 | value: newFileWorkflowModelModule.NewFileWorkflowModel | ||
39 | }, | ||
40 | |||
41 | showNewFileDialog:{ | ||
42 | writable:false, | ||
43 | enumerable:true, | ||
44 | value:function(data){ | ||
45 | //get default project type | ||
46 | this.model.defaultProjectType = "htmlTemplate"; | ||
47 | this.model.callback = data.callback || null; | ||
48 | this.model.callbackScope = data.callbackScope || null; | ||
49 | |||
50 | //populate the last opened folder first, if none then populate default root | ||
51 | var sessionStorage = window.sessionStorage; | ||
52 | var lastSelectedProjectType = sessionStorage.getItem("lastSelectedProjectType"); | ||
53 | |||
54 | if(!!lastSelectedProjectType){ | ||
55 | this.model.defaultProjectType = lastSelectedProjectType; | ||
56 | } | ||
57 | |||
58 | //render modal dialog | ||
59 | var newFileNavContent = document.createElement("div"); | ||
60 | newFileNavContent.id = "newFileDialog"; | ||
61 | |||
62 | //elements needs to be on DOM to be drawn | ||
63 | document.getElementById('modalContainer').appendChild(newFileNavContent); | ||
64 | |||
65 | var newFileOptionsNav = newFileOptionsNavigatorModule.NewFileOptionsNavigator.create(); | ||
66 | newFileOptionsNav.newFileModel = this.model; | ||
67 | newFileOptionsNav.element = newFileNavContent; | ||
68 | |||
69 | //remove after rendering and add in modal dialog | ||
70 | document.getElementById('modalContainer').removeChild(newFileNavContent); | ||
71 | |||
72 | var popup = Popup.create(); | ||
73 | popup.content = newFileOptionsNav; | ||
74 | popup.modal = true; | ||
75 | popup.type = "newFileDialog"; | ||
76 | popup.show(); | ||
77 | |||
78 | newFileOptionsNav.popup = popup;//handle to be used for hiding the popup | ||
79 | |||
80 | } | ||
81 | }, | ||
82 | |||
83 | showSaveAsDialog:{ | ||
84 | writable:false, | ||
85 | enumerable:true, | ||
86 | value:function(data){ | ||
87 | var fileName = data.fileName || "filename.txt"; | ||
88 | var folderUri = data.folderUri || "/Documents"; | ||
89 | |||
90 | //render modal dialog | ||
91 | var saveAsDialogContainer = document.createElement("div"); | ||
92 | saveAsDialogContainer.id = "saveAsDialog"; | ||
93 | |||
94 | //elements needs to be on DOM to be drawn | ||
95 | document.getElementById('modalContainer').appendChild(saveAsDialogContainer); | ||
96 | |||
97 | var saveAsDialog = saveAsModule.SaveAsDialog.create(); | ||
98 | saveAsDialog.fileName = fileName; | ||
99 | saveAsDialog.folderUri = folderUri; | ||
100 | saveAsDialog.callback = data.callback; | ||
101 | saveAsDialog.callbackScope = data.callbackScope; | ||
102 | saveAsDialog.element = saveAsDialogContainer; | ||
103 | |||
104 | //remove after rendering and add in modal dialog | ||
105 | document.getElementById('modalContainer').removeChild(saveAsDialogContainer); | ||
106 | |||
107 | var popup = Popup.create(); | ||
108 | popup.content = saveAsDialog; | ||
109 | popup.modal = true; | ||
110 | popup.type = "saveAsDialog"; | ||
111 | popup.show(); | ||
112 | |||
113 | saveAsDialog.popup = popup;//handle to be used for hiding the popup | ||
114 | } | ||
115 | } | ||
116 | }); \ No newline at end of file | ||