Эх сурвалжийг харах

HUE-841 [core] i18n of fileuploader plugin

Extracted global labels for jHueFileChooser
Removed showusername plugin
Enrico Berti 13 жил өмнө
parent
commit
00b83500c2

+ 18 - 1
desktop/core/src/desktop/templates/common_header.mako

@@ -57,8 +57,25 @@ from django.utils.translation import ugettext as _
     % endif
     % endif
   </style>
   </style>
 
 
+  <script type="text/javascript" charset="utf-8">
+
+      // jHue plugins global configuration
+      jHueFileChooserGlobals = {
+          labels: {
+              BACK: "${_('Back')}",
+              SELECT_FOLDER: "${_('Select this folder')}",
+              CREATE_FOLDER: "${_('Create folder')}",
+              FOLDER_NAME: "${_('Folder name')}",
+              CANCEL: "${_('Cancel')}",
+              FILE_NOT_FOUND: "${_('The file has not been found')}",
+              UPLOAD_FILE: "${_('Upload a file')}",
+              FAILED: "${_('Failed')}"
+          }
+      };
+
+  </script>
+
   <script src="/static/ext/js/jquery/jquery-1.8.1.min.js"></script>
   <script src="/static/ext/js/jquery/jquery-1.8.1.min.js"></script>
-  <script src="/static/js/Source/jHue/jquery.showusername.js"></script>
   <script src="/static/js/Source/jHue/jquery.filechooser.js"></script>
   <script src="/static/js/Source/jHue/jquery.filechooser.js"></script>
   <script src="/static/js/Source/jHue/jquery.selector.js"></script>
   <script src="/static/js/Source/jHue/jquery.selector.js"></script>
   <script src="/static/js/Source/jHue/jquery.alert.js"></script>
   <script src="/static/js/Source/jHue/jquery.alert.js"></script>

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

@@ -5,6 +5,8 @@
 (function ($, window, document, undefined) {
 (function ($, window, document, undefined) {
 
 
     var pluginName = "jHueFileChooser",
     var pluginName = "jHueFileChooser",
+        // global variables (jHueFileChooserGlobals, useful for i18n) can be set on
+        // desktop/templates/common_header.mako
         defaults = {
         defaults = {
             initialPath:"",
             initialPath:"",
             createFolder:true,
             createFolder:true,
@@ -16,7 +18,9 @@
                 CREATE_FOLDER: "Create folder",
                 CREATE_FOLDER: "Create folder",
                 FOLDER_NAME: "Folder name",
                 FOLDER_NAME: "Folder name",
                 CANCEL: "Cancel",
                 CANCEL: "Cancel",
-                FILE_NOT_FOUND: "The file has not been found"
+                FILE_NOT_FOUND: "The file has not been found",
+                UPLOAD_FILE: "Upload a file",
+                FAILED: "Failed"
             },
             },
             onFileChoose:function () {
             onFileChoose:function () {
             },
             },
@@ -28,7 +32,20 @@
 
 
     function Plugin(element, options) {
     function Plugin(element, options) {
         this.element = element;
         this.element = element;
-        this.options = $.extend({}, defaults, options);
+        if (typeof jHueFileChooserGlobals != 'undefined') {
+            var extendedDefaults = $.extend({}, defaults, jHueFileChooserGlobals);
+            extendedDefaults.labels = $.extend({}, defaults.labels, jHueFileChooserGlobals.labels);
+            this.options = $.extend({}, extendedDefaults, options);
+            if (options != null){
+                this.options.labels = $.extend({}, extendedDefaults.labels, options.labels);
+            }
+        }
+        else {
+            this.options = $.extend({}, defaults, options);
+            if (options != null){
+                this.options.labels = $.extend({}, defaults.labels, options.labels);
+            }
+        }
         this._defaults = defaults;
         this._defaults = defaults;
         this._name = pluginName;
         this._name = pluginName;
         this.previousPath = "";
         this.previousPath = "";
@@ -123,7 +140,7 @@
                     _uploadFileBtn = $("<div>").attr("id", "file-uploader");
                     _uploadFileBtn = $("<div>").attr("id", "file-uploader");
                     _uploadFileBtn.appendTo(_actions);
                     _uploadFileBtn.appendTo(_actions);
                     _showActions = true;
                     _showActions = true;
-                    initUploader(path, _parent, _uploadFileBtn);
+                    initUploader(path, _parent, _uploadFileBtn, _parent.options.labels);
                 }
                 }
                 if (_parent.options.selectFolder) {
                 if (_parent.options.selectFolder) {
                     _selectFolderBtn = $("<a>").addClass("btn").addClass("small").text(_parent.options.labels.SELECT_FOLDER);
                     _selectFolderBtn = $("<a>").addClass("btn").addClass("small").text(_parent.options.labels.SELECT_FOLDER);
@@ -206,7 +223,7 @@
     };
     };
 
 
     var num_of_pending_uploads = 0;
     var num_of_pending_uploads = 0;
-    function initUploader(path, _parent, el) {
+    function initUploader(path, _parent, el, labels) {
         var uploader = new qq.FileUploader({
         var uploader = new qq.FileUploader({
             element:el[0],
             element:el[0],
             action:'/filebrowser/upload',
             action:'/filebrowser/upload',
@@ -223,6 +240,18 @@
             onSubmit: function(id, fileName){
             onSubmit: function(id, fileName){
                 num_of_pending_uploads++;
                 num_of_pending_uploads++;
             },
             },
+            template: '<div class="qq-uploader">' +
+                '<div class="qq-upload-drop-area"><span></span></div>' +
+                '<div class="qq-upload-button">' + labels.UPLOAD_FILE + '</div>' +
+                '<ul class="qq-upload-list"></ul>' +
+                '</div>',
+            fileTemplate: '<li>' +
+                '<span class="qq-upload-file"></span>' +
+                '<span class="qq-upload-spinner"></span>' +
+                '<span class="qq-upload-size"></span>' +
+                '<a class="qq-upload-cancel" href="#">' + labels.CANCEL + '</a>' +
+                '<span class="qq-upload-failed-text">' + labels.FAILED + '</span>' +
+                '</li>',
             debug:false
             debug:false
         });
         });
     }
     }

+ 0 - 73
desktop/core/static/js/Source/jHue/jquery.showusername.js

@@ -1,73 +0,0 @@
-/*
----
-description: Gets the logged user info
-requires: [jQuery]
-script: jquery.showusername.js
-...
-*/
-// Licensed to Cloudera, Inc. under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  Cloudera, Inc. licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-;(function ($, window, document, undefined) {
-
-	var pluginName = "jHueUsername",
-	defaults = {
-		onLoad: function(){}
-	};
-
-	function Plugin(element, options) {
-		this.element = element;
-		this.options = $.extend({}, defaults, options) ;
-		this._defaults = defaults;
-		this._name = pluginName;
-		this.init();
-	}
-	
-	Plugin.prototype.setOptions = function(options) {
-		this.options = $.extend({}, defaults, options) ;
-	};
-
-	Plugin.prototype.init = function () {
-        var _this = this;
-        var elem = $(_this.element);
-        if (elem.data("user")!=null && elem.data("user")["username"]){
-            elem.text(elem.data("user")["username"]);
-        }
-        else {
-            $.post(
-                "/profile", function(user){
-                    // sets a user field value the 
-                    elem.data("user", user);
-                    elem.text(elem.data("user")["username"]);
-                    _this.options.onLoad(user);
-                }, "json").error(function(e){
-                    // we get an error when the user is not logged in
-                    elem.data("user", null);
-            });
-        }
-	};
-
-	$.fn[pluginName] = function (options) {
-		return this.each(function () {
-			if (!$.data(this, 'plugin_' + pluginName)) {
-				$.data(this, 'plugin_' + pluginName, new Plugin( this, options));
-			}
-			else {
-				$.data(this, 'plugin_' + pluginName).setOptions(options);
-			}
-		});
-	}
-
-})(jQuery, window, document );