diff options
author | Jose Antonio Marquez | 2012-02-15 20:37:48 -0800 |
---|---|---|
committer | Jose Antonio Marquez | 2012-02-15 20:37:48 -0800 |
commit | 89b5e793ea88ef235b54b6e1d1c379698d3e612b (patch) | |
tree | 4d29118f35df77ca6b423119a4ff61694a442cbf /js/components/ui/FilePicker/file-input-field.reel/file-input-field.js | |
parent | 9d2c2a80483415d7560b00cda5519153db23e241 (diff) | |
parent | d366c0bd1af6471511217ed574083e15059519b5 (diff) | |
download | ninja-89b5e793ea88ef235b54b6e1d1c379698d3e612b.tar.gz |
Merge branch 'refs/heads/NinjaInternal' into Color
Diffstat (limited to 'js/components/ui/FilePicker/file-input-field.reel/file-input-field.js')
-rwxr-xr-x | js/components/ui/FilePicker/file-input-field.reel/file-input-field.js | 120 |
1 files changed, 120 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..235be8ad --- /dev/null +++ b/js/components/ui/FilePicker/file-input-field.reel/file-input-field.js | |||
@@ -0,0 +1,120 @@ | |||
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 | Component = require("montage/ui/component").Component; | ||
9 | |||
10 | var 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("keyup", function(evt){that.handleNewFileDirectoryOnkeyup(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.bind(this); | ||
74 | openFilePicker.settings = settings; | ||
75 | this.eventManager.dispatchEvent(openFilePicker); | ||
76 | } | ||
77 | }, | ||
78 | |||
79 | handleNewFileDirectoryOnkeyup:{ | ||
80 | value:function(evt){ | ||
81 | if(this.newFileDirectory.value !== ""){ | ||
82 | var newFileDirectorySetEvent = document.createEvent("Events"); | ||
83 | newFileDirectorySetEvent.initEvent("newFileDirectorySet", false, false); | ||
84 | newFileDirectorySetEvent.newFileDirectory = this.newFileDirectory.value; | ||
85 | this.eventManager.dispatchEvent(newFileDirectorySetEvent); | ||
86 | } | ||
87 | } | ||
88 | }, | ||
89 | |||
90 | handleFileInputPickerSelectionsDone:{ | ||
91 | value: function(evt){ | ||
92 | var selectedUri = ""; | ||
93 | if(!!evt._event.selectedItems && evt._event.selectedItems.length > 0){ | ||
94 | selectedUri = evt._event.selectedItems[0]; | ||
95 | this.newFileDirectory.value = selectedUri; | ||
96 | |||
97 | var newFileDirectorySetEvent = document.createEvent("Events"); | ||
98 | newFileDirectorySetEvent.initEvent("newFileDirectorySet", false, false); | ||
99 | newFileDirectorySetEvent.newFileDirectory = this.newFileDirectory.value; | ||
100 | this.eventManager.dispatchEvent(newFileDirectorySetEvent); | ||
101 | } | ||
102 | } | ||
103 | }, | ||
104 | |||
105 | filePickerCallback:{ | ||
106 | value: function(obj){ | ||
107 | var selectedUri = ""; | ||
108 | if(!!obj && obj.uri && obj.uri.length > 0){ | ||
109 | selectedUri = obj.uri[0]; | ||
110 | this.newFileDirectory.value = selectedUri; | ||
111 | |||
112 | var newFileDirectorySetEvent = document.createEvent("Events"); | ||
113 | newFileDirectorySetEvent.initEvent("newFileDirectorySet", false, false); | ||
114 | newFileDirectorySetEvent.newFileDirectory = this.newFileDirectory.value; | ||
115 | this.eventManager.dispatchEvent(newFileDirectorySetEvent); | ||
116 | } | ||
117 | } | ||
118 | } | ||
119 | |||
120 | }); \ No newline at end of file | ||