aboutsummaryrefslogtreecommitdiff
path: root/js/components/ui/FilePicker/file-input-field.reel/file-input-field.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/components/ui/FilePicker/file-input-field.reel/file-input-field.js')
-rwxr-xr-xjs/components/ui/FilePicker/file-input-field.reel/file-input-field.js121
1 files changed, 121 insertions, 0 deletions
diff --git a/js/components/ui/FilePicker/file-input-field.reel/file-input-field.js b/js/components/ui/FilePicker/file-input-field.reel/file-input-field.js
new file mode 100755
index 00000000..f832e618
--- /dev/null
+++ b/js/components/ui/FilePicker/file-input-field.reel/file-input-field.js
@@ -0,0 +1,121 @@
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 Component = require("montage/ui/component").Component;
9
10var FileInputField = exports.FileInputField = Montage.create(Component, {
11
12 hasReel: {
13 value: true
14 },
15
16 willDraw: {
17 enumerable: false,
18 value: function() {}
19 },
20 draw: {
21 enumerable: false,
22 value: function() {}
23 },
24 didDraw: {
25 enumerable: false,
26 value: function() {
27 var that = this;
28 this.findDirectory.identifier = "findDirectory";
29 this.findDirectory.addEventListener("click", function(evt){that.handleFindDirectoryClick(evt);}, false);
30
31 this.eventManager.addEventListener("pickerSelectionsDone", function(evt){that.handleFileInputPickerSelectionsDone(evt);}, false);
32
33 this.newFileDirectory.addEventListener("blur", function(evt){that.handleNewFileDirectoryOnblur(evt);}, false);
34 }
35 },
36
37 /**
38 * Either selectDirectory OR selectFile can be true
39 * If both are false then the file picker will default to file selection mode
40 */
41
42 selectDirectory:{
43 writable: true,
44 enumerable:false,
45 value: false
46 },
47
48 pickerName:{
49 writable: true,
50 enumerable:false,
51 value: null
52 },
53
54 selectFile:{
55 writable: true,
56 enumerable:false,
57 value: false
58 },
59
60
61 handleFindDirectoryClick: {
62 value: function(evt){
63 var openFilePicker = document.createEvent("Events");
64 openFilePicker.initEvent("openFilePicker", false, false);
65 var settings = {};
66 if(this.selectDirectory === true){
67 settings.inFileMode = false;
68 settings.pickerName = this.pickerName || "newFileDirectorySelector";
69 }else{
70 settings.inFileMode = true;
71 settings.pickerName = this.pickerName || "fileSelector";
72 }
73 settings.callback = this.filePickerCallback;
74 settings.callbackScope = this;
75 openFilePicker.settings = settings;
76 this.eventManager.dispatchEvent(openFilePicker);
77 }
78 },
79
80 handleNewFileDirectoryOnblur:{
81 value:function(evt){
82 if(this.newFileDirectory.value !== ""){
83 var newFileDirectorySetEvent = document.createEvent("Events");
84 newFileDirectorySetEvent.initEvent("newFileDirectorySet", false, false);
85 newFileDirectorySetEvent.newFileDirectory = this.newFileDirectory.value;
86 this.eventManager.dispatchEvent(newFileDirectorySetEvent);
87 }
88 }
89 },
90
91 handleFileInputPickerSelectionsDone:{
92 value: function(evt){
93 var selectedUri = "";
94 if(!!evt._event.selectedItems && evt._event.selectedItems.length > 0){
95 selectedUri = evt._event.selectedItems[0];
96 this.newFileDirectory.value = selectedUri;
97
98 var newFileDirectorySetEvent = document.createEvent("Events");
99 newFileDirectorySetEvent.initEvent("newFileDirectorySet", false, false);
100 newFileDirectorySetEvent.newFileDirectory = this.newFileDirectory.value;
101 this.eventManager.dispatchEvent(newFileDirectorySetEvent);
102 }
103 }
104 },
105
106 filePickerCallback:{
107 value: function(obj){
108 var selectedUri = "";
109 if(!!obj && obj.uri && obj.uri.length > 0){
110 selectedUri = obj.uri[0];
111 this.newFileDirectory.value = selectedUri;
112
113 var newFileDirectorySetEvent = document.createEvent("Events");
114 newFileDirectorySetEvent.initEvent("newFileDirectorySet", false, false);
115 newFileDirectorySetEvent.newFileDirectory = this.newFileDirectory.value;
116 this.eventManager.dispatchEvent(newFileDirectorySetEvent);
117 }
118 }
119 }
120
121}); \ No newline at end of file