aboutsummaryrefslogtreecommitdiff
path: root/js/io/workflow/save-as-dialog.reel/save-as-dialog.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/io/workflow/save-as-dialog.reel/save-as-dialog.js')
-rwxr-xr-xjs/io/workflow/save-as-dialog.reel/save-as-dialog.js126
1 files changed, 126 insertions, 0 deletions
diff --git a/js/io/workflow/save-as-dialog.reel/save-as-dialog.js b/js/io/workflow/save-as-dialog.reel/save-as-dialog.js
new file mode 100755
index 00000000..1255a1bd
--- /dev/null
+++ b/js/io/workflow/save-as-dialog.reel/save-as-dialog.js
@@ -0,0 +1,126 @@
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 SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, {
11
12 hasReel: {
13 value: true
14 },
15
16 fileName : {
17 enumerable: true,
18 writable: true,
19 value: ""
20 },
21
22 callback : {
23 enumerable: true,
24 writable: true,
25 value: null
26 },
27
28 callbackScope : {
29 enumerable: true,
30 writable: true,
31 value: null
32 },
33
34 willDraw: {
35 enumerable: false,
36 value: function() {}
37 },
38 draw: {
39 enumerable: false,
40 value: function() {}
41 },
42 didDraw: {
43 enumerable: false,
44 value: function() {
45 this.fileInputField.selectDirectory = true;
46 this.fileInputField.pickerName = "saveAsDirectoryPicker";
47 this.newFileName.value = this.fileName;
48 this.fileInputField.newFileDirectory.value = this.folderUri;
49 }
50 },
51
52 handleCancelButtonAction :{
53 value:function(evt){
54 //clean up memory
55 //this.cleanup();
56
57 if(this.popup){
58 this.popup.hide();
59 }
60
61 }
62 },
63
64 handleOkButtonAction:{
65 value: function(evt){
66 var filename = this.fileName,
67 newFileDirectory = this.newFileDirectory,
68 success = true;
69 try{
70 //validate file name and folder path
71 //check if file already exists
72 if(!!this.callback && !!this.callbackScope){//inform document-controller if save successful
73 this.callback.call(this.callbackScope, {"filename":filename, "destination": newFileDirectory});//document-controller api
74 }else{
75 //send save as event
76 var saveAsEvent = document.createEvent("Events");
77 saveAsEvent.initEvent("saveAsFile", false, false);
78 saveAsEvent.saveAsOptions = {"filename":filename, "destination": newFileDirectory};
79 this.eventManager.dispatchEvent(saveAsEvent);
80 }
81 }catch(e){
82 success = false;
83 console.log("[ERROR] Failed to save: "+ this.fileName + " at "+ this.newFileDirectory);
84 }
85
86 if(success){
87 //clean up memory
88 //this.cleanup();
89
90 if(this.popup){
91 this.popup.hide();
92 }
93 }
94 }
95 },
96
97 isValidUri:{
98 value: function(uri){
99 var isWindowsUri=false, isUnixUri=false,status=false;
100 if(uri !== ""){
101 uri = uri.replace(/^\s+|\s+$/g,""); // strip any leading or trailing spaces
102
103 //for local machine folder uri
104 isWindowsUri = /^([a-zA-Z]:)(\\[^<>:"/\\|?*]+)*\\?$/gi.test(uri);
105 isUnixUri = /^(\/)?(\/(?![.])[^/]*)*\/?$/gi.test(uri);//folders beginning with . are hidden on Mac / Unix
106 status = isWindowsUri || isUnixUri;
107 if(isWindowsUri && isUnixUri){status = false;}
108 }
109 return status;
110 }
111 },
112 isValidFileName:{
113 value: function(fileName){
114 var status = false;
115 if(fileName !== ""){
116 fileName = fileName.replace(/^\s+|\s+$/g,"");
117 status = !(/[/\\]/g.test(fileName));
118 if(status && navigator.userAgent.indexOf("Macintosh") != -1){//for Mac files beginning with . are hidden
119 status = !(/^\./g.test(fileName));
120 }
121 }
122 return status;
123 }
124 }
125
126}); \ No newline at end of file