+ toggleFavorites: function() {
+ var $btn = this.$favorites,
+ locations = this.hostSelectize,
+ is_active = $btn.hasClass('active'),
+ url = is_active ? '/filex/fav/delete/' : '/filex/fav/add/',
+ data = {
+ host: this.host,
+ path: this.path.full()
+ };
+
+ $btn.button('loading');
+
+ $.post(url, data, 'json').done(function () {
+ $btn.button('reset');
+
+ if (is_active) {
+ locations.removeOption(data.host + data.path);
+ }
+ else {
+ locations.addOption({
+ group: 'usr',
+ host: data.host,
+ path: data.path,
+ value: data.host + data.path
+ });
+ }
+ }).fail(function() {
+ $btn.button('reset');
+ $btn.button('toggle');
+
+ console.error(arguments);
+ });
+ },
+
+ initialLoad: function() {
+ if (!this.host) {
+ var opts = this.hostSelectize.options;
+
+ this.load(opts[Object.keys(opts)[0]].value);
+ }
+ },
+
+ changedPath: function () {
+ this.reloadFiles();
+ this.updateFavorites();
+ },
+
+ updateFavorites: function() {
+ var loc = this.host + this.path.full(),
+ favorites = this.hostSelectize.options;
+
+ if (favorites.hasOwnProperty(loc)) {
+ if (favorites[loc].group == 'sys') {
+ this.$favorites.addClass('disabled').prop('disabled', true);
+ if (this.$favorites.hasClass('active'))
+ this.$favorites.button('toggle');
+ }
+ else {
+ this.$favorites.removeClass('disabled').prop('disabled', false);
+ if (!this.$favorites.hasClass('active'))
+ this.$favorites.button('toggle');
+ }
+ }
+ else {
+ this.$favorites.removeClass('disabled').prop('disabled', false);
+ if (this.$favorites.hasClass('active'))
+ this.$favorites.button('toggle');
+ }
+ },
+
+ editHost: function() {
+ $('#host').addClass('edit');
+ this.hostSelectize.focus();