// 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. /* * jHue fileChooser plugin */ ; (function ($, window, document, undefined) { var pluginName = "jHueFileChooser", // global variables (jHueFileChooserGlobals, useful for i18n) can be set on // desktop/templates/common_header.mako defaults = { initialPath:"", forceRefresh:false, errorRedirectPath:"", createFolder:true, uploadFile:true, selectFolder:false, suppressErrors:false, 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" }, user: "", onFileChoose:function () { }, onFolderChoose:function () { }, onFolderChange:function () { }, onError:function () { } }, STORAGE_PREFIX = "hueFileBrowserLastPathForUser_"; function Plugin(element, options) { this.element = element; 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._name = pluginName; this.previousPath = ""; this.init(); } Plugin.prototype.setOptions = function (options) { this.options = $.extend({}, defaults, options); if (this.options.forceRefresh){ if ($.trim(this.options.initialPath) != "") { this.navigateTo(this.options.initialPath); } else if ($.totalStorage(STORAGE_PREFIX + this.options.user) != null) { this.navigateTo($.totalStorage(STORAGE_PREFIX + this.options.user)); } else { this.navigateTo("/?default_to_home"); } } else { if ($.trim(this.options.initialPath) != "") { this.navigateTo(this.options.initialPath); } } }; Plugin.prototype.navigateTo = function (path) { var _parent = this; if (navigator.userAgent.match(/msie/i)) { $(_parent.element).html(""); } else { $(_parent.element).html(""); } $.getJSON("/filebrowser/chooser" + path, function (data) { $(_parent.element).empty(); path = data.current_dir_path; // use real path. var _flist = $("