浏览代码

HUE-1238 [jobsub] Select path

- Provide file, directory, and path selection.
- deletes, chmod, move, and script path should use path.
- use class name to discern between different kinds of selection windows.
Abraham Elmahrek 12 年之前
父节点
当前提交
55844c1302

+ 27 - 1
apps/jobsub/src/jobsub/templates/designs.mako

@@ -235,7 +235,33 @@ ${ commonheader(None, "jobsub", user, "60px") | n,unicode }
     <h3>${_('Choose a file')}</h3>
   </div>
   <div class="modal-body">
-    <div id="fileChooserModal">
+    <div class="chooser">
+    </div>
+  </div>
+  <div class="modal-footer">
+  </div>
+</div>
+
+<div id="chooseDirectory" class="modal hide fade">
+  <div class="modal-header">
+    <a href="#" class="close" data-dismiss="modal">&times;</a>
+    <h3>${_('Choose a directory')}</h3>
+  </div>
+  <div class="modal-body">
+    <div class="chooser">
+    </div>
+  </div>
+  <div class="modal-footer">
+  </div>
+</div>
+
+<div id="choosePath" class="modal hide fade">
+  <div class="modal-header">
+    <a href="#" class="close" data-dismiss="modal">&times;</a>
+    <h3>${_('Choose a path')}</h3>
+  </div>
+  <div class="modal-body">
+    <div class="chooser">
     </div>
   </div>
   <div class="modal-footer">

+ 34 - 26
apps/jobsub/static/js/jobsub.js

@@ -140,30 +140,31 @@ function showSection(section) {
   $('.section').hide();
   $('#' + section).show();
   $(window).scrollTop(0);
-
-  // Filechooser.
-  $(".pathChooserKo").each(function(){
-    var self = $(this);
-    self.after(getFileBrowseButton(self, false));
-  });
-
-  $(".pathFolderChooserKo").each(function(){
-    var self = $(this);
-    self.after(getFileBrowseButton(self, true));
-  });
+  addFileBrowseButton();
 }
 
-function getFileBrowseButton(inputElement, isFolder) {
-  return $("<button>").addClass("btn").addClass("fileChooserBtn").text("..").click(function(e){
+function getFileBrowseButton(inputElement, folderSelectable, fileSelectable, uploadFile, createFolder) {
+  var modal = null;
+  if (fileSelectable && folderSelectable) {
+    modal = "#choosePath";
+  } else if (folderSelectable) {
+    modal = "#chooseDirectory";
+  } else {
+    modal = "#chooseFile";
+  }
+  var chooser = modal + " .chooser";
+
+  return $("<button>").addClass("btn").addClass("chooserBtn").text("..").click(function(e){
     e.preventDefault();
-    $("#fileChooserModal").jHueFileChooser({
+
+    $(chooser).jHueFileChooser({
       initialPath: inputElement.val(),
       onFileChoose: function(filePath) {
-        if (!isFolder){
+        if (fileSelectable){
           inputElement.val(filePath);
           inputElement.change();
           addFileBrowseButton();
-          $("#chooseFile").modal("hide");
+          $(modal).modal("hide");
         }
       },
       onFolderChange: function(filePath) {
@@ -171,19 +172,19 @@ function getFileBrowseButton(inputElement, isFolder) {
         inputElement.change();
       },
       onFolderChoose: function(filePath) {
-        if (isFolder){
+        if (folderSelectable){
           inputElement.val(filePath);
           inputElement.change();
           addFileBrowseButton();
-          $("#chooseFile").modal("hide");
+          $(modal).modal("hide");
         }
       },
-      createFolder: isFolder,
-      selectFolder: isFolder,
-      uploadFile: !isFolder,
+      createFolder: createFolder,
+      selectFolder: folderSelectable,
+      uploadFile: uploadFile,
       forceRefresh: true
     });
-    $("#chooseFile").modal("show");
+    $(modal).modal("show");
   })
 }
 
@@ -191,15 +192,22 @@ function addFileBrowseButton() {
   // Filechooser.
   $(".pathChooserKo").each(function(){
     var self = $(this);
-    if (!self.siblings().hasClass('fileChooserBtn')) {
-      self.after(getFileBrowseButton(self, false));
+    if (!self.siblings().hasClass('chooserBtn')) {
+      self.after(getFileBrowseButton(self, true, true, false, true));
+    }
+  });
+
+  $(".pathFileChooserKo").each(function(){
+    var self = $(this);
+    if (!self.siblings().hasClass('chooserBtn')) {
+      self.after(getFileBrowseButton(self, false, true, true, false));
     }
   });
 
   $(".pathFolderChooserKo").each(function(){
     var self = $(this);
-    if (!self.siblings().hasClass('fileChooserBtn')) {
-      self.after(getFileBrowseButton(self, true));
+    if (!self.siblings().hasClass('chooserBtn')) {
+      self.after(getFileBrowseButton(self, true, false, false, true));
     }
   });
 }

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

@@ -45,7 +45,7 @@ var Templates = (function($, ko) {
         archives: 'static/templates/widgets/filechooser.html',
         files: 'static/templates/widgets/filechooser.html',
         mkdirs: 'static/templates/widgets/folderchooser.html',
-        deletes: 'static/templates/widgets/folderchooser.html',
+        deletes: 'static/templates/widgets/pathchooser.html',
         touchzs: 'static/templates/widgets/filechooser.html',
         chmods: 'static/templates/widgets/chmods.html',
         moves: 'static/templates/widgets/moves.html',

+ 1 - 1
apps/jobsub/static/templates/actions/hive.html

@@ -37,7 +37,7 @@
       <div class="control-group" rel="popover" data-original-title="{{ script_path.name }}" data-content="{{ script_path.popover }}" data-bind="attr: {'class': ( errors.script_path().length > 0 ) ? 'control-group error' : 'control-group'}">
         <label class="control-label">{{ script_path.name }}</label>
         <div class="controls">
-          <input id="hive-script-path" type="text" class="pathChooserKo" name="script-path" data-bind="fileChooser: $data, value: script_path" />
+          <input id="hive-script-path" type="text" class="pathFileChooserKo" name="script-path" data-bind="fileChooser: $data, value: script_path" />
           <ul class="help-inline" data-bind="foreach: errors.script_path()">
             <li class="error" data-bind="html: $data"></li>
           </ul>

+ 1 - 1
apps/jobsub/static/templates/actions/pig.html

@@ -37,7 +37,7 @@
       <div class="control-group" rel="popover" data-original-title="{{ script_path.name }}" data-content="{{ script_path.popover }}" data-bind="attr: {'class': ( errors.script_path().length > 0 ) ? 'control-group error' : 'control-group'}">
         <label class="control-label">{{ script_path.name }}</label>
         <div class="controls">
-          <input id="pig-script-path" type="text" class="pathChooserKo" name="script-path" data-bind="fileChooser: $data, value: script_path" />
+          <input id="pig-script-path" type="text" class="pathFileChooserKo" name="script-path" data-bind="fileChooser: $data, value: script_path" />
           <ul class="help-inline" data-bind="foreach: errors.script_path()">
             <li class="error" data-bind="html: $data"></li>
           </ul>

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

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

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

@@ -4,7 +4,7 @@
 	  <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 pathChooserKo" data-bind="fileChooser: $data, value: name, uniqueName: false" /></td>
+	        <td><input type="text" class="input span5 required pathFileChooserKo" 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>

+ 2 - 2
apps/jobsub/static/templates/widgets/moves.html

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

+ 14 - 0
apps/jobsub/static/templates/widgets/pathchooser.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 pathChooserKo" 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>