Browse Source

HUE-836 [fb] Add folder selector to move operation popup

Added select folder and create folder buttons
Put button selector instead of onfocus
Enrico Berti 13 years ago
parent
commit
25512ec9cd

+ 7 - 3
apps/filebrowser/src/filebrowser/templates/editor_components.mako

@@ -33,7 +33,8 @@
   dt_attrs=None,
   title_klass=None,
   button_text=False,
-  nolabel=False
+  nolabel=False,
+  file_chooser=False,
   )">
 <%
   if value is None:
@@ -89,7 +90,11 @@
         % elif hidden:
           <input type="hidden" name="${field.html_name | n}" ${make_attr_str(attrs) | n} value="${extract_field_data(field)}"></input>
         % else:
-          <${tag} name="${field.html_name | n}" value="${extract_field_data(field) or ''}" class="${cls}" ${make_attr_str(attrs) | n}/>
+          %if file_chooser:
+            <${tag} type="text" name="${field.html_name | n}" value="${extract_field_data(field) or ''}" class="${cls}" ${make_attr_str(attrs) | n}/><a class="btn fileChooserBtn" href="#" data-filechooser-destination="${field.html_name | n}">..</a>
+          %else:
+            <${tag} type="text" name="${field.html_name | n}" value="${extract_field_data(field) or ''}" class="${cls}" ${make_attr_str(attrs) | n}/>
+          %endif
         % endif
       % endif
       % if help:
@@ -102,4 +107,3 @@
       </div>
     % endif
 </%def>
-

+ 12 - 9
apps/filebrowser/src/filebrowser/templates/move.mako

@@ -26,7 +26,7 @@ from django.utils.translation import ugettext as _
     <div class="modal-body">
         <div style="padding-left: 15px;">
         ${edit.render_field(form["src_path"], hidden=True)}
-        ${edit.render_field(form["dest_path"], notitle=True, klass="input-xlarge pathChooser")}
+        <label for="id_dest_path">${_('Destination')}</label>${edit.render_field(form["dest_path"], notitle=True, nolabel=True, klass="input-xlarge pathChooser", file_chooser=True)}
         </div>
         <br/>
         <div id="fileChooserModal" class="smallModal well hide">
@@ -43,17 +43,20 @@ from django.utils.translation import ugettext as _
 </form>
 
 <script type="text/javascript" charset="utf-8">
-    $(".pathChooser").click(function(){
-        var self = this;
+    $(".fileChooserBtn").click(function(e){
+        e.preventDefault();
+        var _destination = $(this).attr("data-filechooser-destination");
         $("#fileChooserModal").jHueFileChooser({
-            initialPath: $(self).val(),
-            onFileChoose: function(filePath) {
-                $(self).val(filePath);
-            },
+            initialPath: $("input[name='"+_destination+"']").val(),
             onFolderChange: function(folderPath){
-                $(self).val(folderPath);
+                $("input[name='"+_destination+"']").val(folderPath);
+            },
+            onFolderChoose: function(folderPath){
+                $("input[name='"+_destination+"']").val(folderPath);
+                $("#fileChooserModal").slideUp();
             },
-            createFolder: false,
+            selectFolder: true,
+            createFolder: true,
             uploadFile: false
         });
         $("#fileChooserModal").slideDown();

+ 4 - 3
desktop/core/static/js/Source/jHue/jquery.filechooser.js

@@ -50,7 +50,7 @@
             if (data.title != null && data.title == "Error") {
                 var _errorMsg = $("<div>").addClass("alert").addClass("alert-error").text(data.message);
                 _errorMsg.appendTo($(_parent.element));
-                var _previousLink = $("<button>").addClass("btn").addClass("bnt-small").text(_parent.options.labels.BACK).click(function () {
+                var _previousLink = $("<a>").addClass("btn").addClass("bnt-small").text(_parent.options.labels.BACK).click(function () {
                     _parent.options.onFolderChange(_parent.previousPath);
                     _parent.navigateTo(_parent.previousPath);
                 });
@@ -87,6 +87,7 @@
                     }
                     _crumb.click(function () {
                         var _url = (crumb.url != null && crumb.url != "") ? crumb.url : "/";
+                        _parent.options.onFolderChange(_url);
                         _parent.navigateTo(_url);
                     });
                     _crumb.appendTo(_breadcrumbs);
@@ -125,7 +126,7 @@
                     initUploader(path, _parent, _uploadFileBtn);
                 }
                 if (_parent.options.selectFolder) {
-                    _selectFolderBtn = $("<button>").addClass("btn").addClass("small").text(_parent.options.labels.SELECT_FOLDER);
+                    _selectFolderBtn = $("<a>").addClass("btn").addClass("small").text(_parent.options.labels.SELECT_FOLDER);
                     if (_parent.options.uploadFile){
                         _selectFolderBtn.css("margin-top", "10px");
                     }
@@ -137,7 +138,7 @@
                 }
                 $("<span> </span>").appendTo(_actions);
                 if (_parent.options.createFolder) {
-                    _createFolderBtn = $("<button>").addClass("btn").addClass("small").text(_parent.options.labels.CREATE_FOLDER);
+                    _createFolderBtn = $("<a>").addClass("btn").addClass("small").text(_parent.options.labels.CREATE_FOLDER);
                     if (_parent.options.uploadFile){
                         _createFolderBtn.css("margin-top", "10px");
                     }