Преглед изворни кода

HUE-1216 [jobsub] File dialogs consistency

Differentiated file chooser with folder chooser
Enrico Berti пре 12 година
родитељ
комит
42cb61f

+ 35 - 6
apps/jobsub/static/js/jobsub.js

@@ -144,22 +144,44 @@ function showSection(section) {
   // Filechooser.
   $(".pathChooserKo").each(function(){
     var self = $(this);
-    self.after(getFileBrowseButton(self));
+    self.after(getFileBrowseButton(self, false));
+  });
+
+  $(".pathFolderChooserKo").each(function(){
+    var self = $(this);
+    self.after(getFileBrowseButton(self, true));
   });
 }
 
-function getFileBrowseButton(inputElement) {
+function getFileBrowseButton(inputElement, isFolder) {
   return $("<button>").addClass("btn").addClass("fileChooserBtn").text("..").click(function(e){
     e.preventDefault();
     $("#fileChooserModal").jHueFileChooser({
       initialPath: inputElement.val(),
       onFileChoose: function(filePath) {
+        if (!isFolder){
+          inputElement.val(filePath);
+          inputElement.change();
+          addFileBrowseButton();
+          $("#chooseFile").modal("hide");
+        }
+      },
+      onFolderChange: function(filePath) {
         inputElement.val(filePath);
         inputElement.change();
-        addFileBrowseButton();
-        $("#chooseFile").modal("hide");
       },
-      createFolder: false
+      onFolderChoose: function(filePath) {
+        if (isFolder){
+          inputElement.val(filePath);
+          inputElement.change();
+          addFileBrowseButton();
+          $("#chooseFile").modal("hide");
+        }
+      },
+      createFolder: isFolder,
+      selectFolder: isFolder,
+      uploadFile: !isFolder,
+      forceRefresh: true
     });
     $("#chooseFile").modal("show");
   })
@@ -170,7 +192,14 @@ function addFileBrowseButton() {
   $(".pathChooserKo").each(function(){
     var self = $(this);
     if (!self.siblings().hasClass('fileChooserBtn')) {
-      self.after(getFileBrowseButton(self));
+      self.after(getFileBrowseButton(self, false));
+    }
+  });
+
+  $(".pathFolderChooserKo").each(function(){
+    var self = $(this);
+    if (!self.siblings().hasClass('fileChooserBtn')) {
+      self.after(getFileBrowseButton(self, true));
     }
   });
 }

+ 4 - 4
apps/jobsub/static/js/jobsub.templates.js

@@ -34,7 +34,7 @@ var Templates = (function($, ko) {
         ssh: 'static/templates/actions/ssh.html',
         shell: 'static/templates/actions/shell.html',
         email: 'static/templates/actions/email.html',
-        distcp: 'static/templates/actions/distcp.html',
+        distcp: 'static/templates/actions/distcp.html'
       },
       partials: {
         name: 'static/templates/widgets/text.html',
@@ -44,8 +44,8 @@ var Templates = (function($, ko) {
         parameters: 'static/templates/widgets/parameters.html',
         archives: 'static/templates/widgets/filechooser.html',
         files: 'static/templates/widgets/filechooser.html',
-        mkdirs: 'static/templates/widgets/filechooser.html',
-        deletes: 'static/templates/widgets/filechooser.html',
+        mkdirs: 'static/templates/widgets/folderchooser.html',
+        deletes: 'static/templates/widgets/folderchooser.html',
         touchzs: 'static/templates/widgets/filechooser.html',
         chmods: 'static/templates/widgets/filechooser.html',
         moves: 'static/templates/widgets/filechooser.html',
@@ -57,7 +57,7 @@ var Templates = (function($, ko) {
         arguments_envvars: 'static/templates/widgets/params.html',
         params_arguments: 'static/templates/widgets/params.html',
         capture_output: 'static/templates/widgets/checkbox.html'
-      },
+      }
     }, options);
 
     self.initialize(options);

+ 14 - 0
apps/jobsub/static/templates/widgets/folderchooser.html

@@ -0,0 +1,14 @@
+<div class="control-group" data-bind="attr: {'class': {{ ko.error_class }} }">
+	<label class="control-label">{{ title }}</label>
+	<div class="controls">
+	  <table class="table-condensed designTable" data-bind="visible: {{ ko.condition }}">
+	    <tbody data-bind="foreach: {{ ko.items }}">
+	      <tr>
+	        <td><input type="text" class="input span5 required pathFolderChooserKo" data-bind="fileChooser: $data, value: name, uniqueName: false" /></td>
+	        <td><a class="btn" href="javascript:void(0);" data-bind="click: {{ delete.func }}">{{ delete.name }}</a></td>
+	      </tr>
+	    </tbody>
+	  </table>
+	  <button class="btn" data-bind="click: {{ add.func }}">{{ add.name }}</button>
+	</div>
+</div>

+ 1 - 1
apps/jobsub/static/templates/widgets/prepares.html

@@ -12,7 +12,7 @@
       <tbody data-bind="foreach: {{ ko.items }}">
         <tr>
           <td data-bind="text: type"></td>
-          <td><input type="text" class="span4 required pathChooserKo" data-bind="fileChooser: $data, value: value, uniqueName: false" /></td>
+          <td><input type="text" class="span4 required pathFolderChooserKo" data-bind="fileChooser: $data, value: value, uniqueName: false" /></td>
           <td><a class="btn btn-small" href="javascript:void(0);" data-bind="click: {{ delete.func }}">{{ delete.name }}</a></td>
         </tr>
       </tbody>

+ 1 - 1
desktop/core/static/css/hue2.css

@@ -948,7 +948,7 @@ div.box {
     border-top: 1px dashed #EEEEEE;
 }
 
-.pathChooser, .pathChooserKo {
+.pathChooser, .pathChooserKo, .pathFolderChooserKo {
     border-radius: 3px 0 0 3px!important;
     border-right:0!important;
 }

+ 9 - 1
desktop/core/static/js/Source/jHue/jquery.filechooser.js

@@ -74,7 +74,15 @@
     Plugin.prototype.setOptions = function (options) {
         this.options = $.extend({}, defaults, options);
         if (this.options.forceRefresh){
-          this.navigateTo(this.options.initialPath);
+          if ($.trim(this.options.initialPath) != "") {
+            this.navigateTo(this.options.initialPath);
+          }
+          else if ($.cookie("hueFileBrowserLastPath") != null) {
+            this.navigateTo($.cookie("hueFileBrowserLastPath"));
+          }
+          else {
+            this.navigateTo("/?default_to_home");
+          }
         }
         else {
           if ($.trim(this.options.initialPath) != "") {