aboutsummaryrefslogtreecommitdiff
path: root/js/components/ui/FilePicker
diff options
context:
space:
mode:
authorPierre Frisch2011-12-22 07:25:50 -0800
committerValerio Virgillito2012-01-27 11:18:17 -0800
commitb89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch)
tree0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /js/components/ui/FilePicker
parent2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff)
downloadninja-b89a7ee8b956c96a1dcee995ea840feddc5d4b27.tar.gz
First commit of Ninja to ninja-internal
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'js/components/ui/FilePicker')
-rw-r--r--js/components/ui/FilePicker/file-picker-controller.js497
-rw-r--r--js/components/ui/FilePicker/file-picker-model.js122
-rw-r--r--js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.css201
-rw-r--r--js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.html81
-rw-r--r--js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js1019
5 files changed, 1920 insertions, 0 deletions
diff --git a/js/components/ui/FilePicker/file-picker-controller.js b/js/components/ui/FilePicker/file-picker-controller.js
new file mode 100644
index 00000000..526578d1
--- /dev/null
+++ b/js/components/ui/FilePicker/file-picker-controller.js
@@ -0,0 +1,497 @@
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
7
8var Montage = require("montage/core/core").Montage,
9 pickerNavigatorReel = require("js/components/ui/FilePicker/pickerNavigator.reel").PickerNavigator,
10 filePickerModelModule = require("js/components/ui/FilePicker/file-picker-model"),
11 fileSystem = require("js/io/system/filesystem").FileSystem,
12 Popup = require("montage/ui/popup/popup.reel").Popup;
13
14//singleton with functions to create a new file picker instance and utilities to format or filter the model data
15var FilePickerController = exports.FilePickerController = Montage.create(require("montage/ui/component").Component, {
16 /**
17 * Register a listener for file open event
18 */
19 deserializedFromTemplate:{
20 writable:false,
21 enumerable:true,
22 value:function(){
23 var that = this;
24 this.eventManager.addEventListener("executeFileOpen", function(evt){
25
26 var callback, pickerMode, currentFilter, allFileFilters,inFileMode, allowNewFileCreation, allowMultipleSelections;
27
28 if(!!evt.callback){
29 callback = evt.callback;
30 }
31 if(!!evt.pickerMode){
32 pickerMode = evt.pickerMode;
33 }
34 if(!!evt.currentFilter){
35 currentFilter = evt.currentFilter;
36 }
37 if(!!evt.inFileMode){
38 inFileMode = evt.inFileMode;
39 }
40 if(!!evt.allFileFilters){
41 allFileFilters = evt.allFileFilters;
42 }
43 if(!!evt.allowNewFileCreation){
44 allowNewFileCreation = evt.allowNewFileCreation;
45 }
46 if(!!evt.allowMultipleSelections){
47 allowMultipleSelections = evt.allowMultipleSelections;
48 }
49
50 that.showFilePicker(callback, pickerMode, currentFilter, allFileFilters,inFileMode, allowNewFileCreation, allowMultipleSelections);
51
52 }, false);
53 }
54 },
55
56 /**
57 * this will be stored in the local storage and in the cloud may be, for the cloud one.
58 */
59 _lastOpenedFolderURI:{
60 writable:true,
61 enumerable:true,
62 value:{
63 lastFolderUri_local:null,
64 lastFolderUri_cloud:null
65 }
66 },
67
68 /**
69 * this will be stored in the local storage and in the cloud may be, for the cloud one.
70 */
71 _lastSavedFolderURI:{
72 writable:true,
73 enumerable:true,
74 value:{
75 lastSavedFolderUri_local:null,
76 lastSavedFolderUri_cloud:null
77 }
78 },
79
80 /**
81 *this function is used to create an instance of a file picker
82 *
83 * parameters:
84 * callback: the call back function which will be used to send the selected URIs back
85 * pickerMode: ["read", "write"] : specifies if the file picker is opened to read a file/folder or to save a file
86 * currentFilter: if a current filter needs to be applied [ex: .psd]
87 * allFileFilters: list of filters that user can use to filter the view
88 * inFileMode: true => allow file selection , false => allow directory selection
89 * allowNewFileCreation: flag to specify whether or not it should return URI(s) to item(s) that do not exist. i.e. a user can type a filename to a new file that doesn't yet exist in the file system.
90 * allowMultipleSelections: allowMultipleSelections
91 *rootDirectories: invoker of this function can mention a subset of the allowed root directories to show in the file picker
92 *
93 * return: none
94 */
95
96 showFilePicker:{
97 writable:false,
98 enumerable:true,
99 value:function(callback, pickerMode, currentFilter, allFileFilters,inFileMode, allowNewFileCreation, allowMultipleSelections){
100
101 var aModel = filePickerModelModule.FilePickerModel.create();
102
103 var topLevelDirectories = null;
104 var driveData = fileSystem.shellApiHandler.getDirectoryContents({uri:"", recursive:false, returnType:"all"});
105 if(driveData.success){
106 topLevelDirectories = (JSON.parse(driveData.content)).children;
107 }else{
108 var errorCause = "";
109 if(driveData.status === null){
110 errorCause = "Service Unavailable"
111 }else{
112 errorCause = driveData.status;
113 }
114 aModel.fatalError = " ** Unable to get files [Error: "+ errorCause +"]";
115 }
116
117 aModel.currentFilter = currentFilter;
118 aModel.inFileMode = inFileMode;
119 aModel.topLevelDirectories = topLevelDirectories;
120
121 if(!!topLevelDirectories && !!topLevelDirectories[0]){
122 aModel.currentRoot = topLevelDirectories[0].uri;
123 }
124
125 //populate the last opened folder first, if none then populate default root
126 var sessionStorage = window.sessionStorage;
127 var storedUri = null;
128
129 if(pickerMode === "write"){
130 storedUri = sessionStorage.getItem("lastSavedFolderURI");
131 }else{
132 storedUri = sessionStorage.getItem("lastOpenedFolderURI");
133 }
134
135 if(!!storedUri){
136 aModel.currentRoot = unescape(storedUri);
137 }
138
139 aModel.fileFilters = allFileFilters;
140 aModel.callback = callback;
141 aModel.pickerMode = pickerMode;
142
143 //dummy data - TODO:remove after testing
144 //aModel.currentFilter = "*.html, *.png";
145 //aModel.currentFilter = "*.jpg";
146 aModel.currentFilter = "*.*";
147 aModel.inFileMode = true;
148 aModel.fileFilters = [".html, .htm", ".jpg, .jpeg, .png, .gif", ".js, .json", ".css", ".txt, .rtf", ".doc, .docx", ".pdf", ".avi, .mov, .mpeg, .ogg, .webm", "*.*"];
149 //-end - dummy data
150
151 //logic: get file content data onDemand from the REST api for the default or last opened root. Cache the data in page [in local cache ? dirty fs? ]. Filter on client side to reduce network calls.
152 this.openFilePickerAsModal(callback, aModel);
153
154
155 //to open this on another modal dialog, make it a popup instead above the modal dialog container layer
156
157 }
158 },
159
160 openFilePickerAsModal:{
161 writable:false,
162 enumerable:true,
163 value:function(callback, aModel){
164 //render modal dialog
165 var pickerNavContent = document.createElement("div");
166 pickerNavContent.id = "filePicker";
167
168 pickerNavContent.style.color = "#fff";
169
170 //hack (elements needs to be on DOM to be drawn)
171 document.getElementById('modalContainer').appendChild(pickerNavContent);
172
173 var pickerNavChoices = Montage.create(pickerNavigatorReel);
174 var initUri = aModel.currentRoot;
175 pickerNavChoices.mainContentData = this.prepareContentList(initUri, aModel);
176 pickerNavChoices.pickerModel = aModel;
177 pickerNavChoices.element = pickerNavContent;
178
179 //hack - remove after rendering and add in modal dialog
180 document.getElementById('modalContainer').removeChild(pickerNavContent);
181
182 var popup = Popup.create();
183 popup.content = pickerNavChoices;
184 popup.modal = true;
185 popup.show();
186
187 pickerNavChoices.popup = popup;//handle to be used for hiding the popup
188 }
189 },
190 openFilePickerAsPopup:{
191 writable:false,
192 enumerable:true,
193 value:function(){}
194 },
195
196 expandDirectory:{
197 writable:false,
198 enumerable:true,
199 value: function(root, currentFilter, inFileMode){
200 //populate children in dom
201 }
202 },