+ updateSelectAll: function() {
+ if (this.visibleFiles().length) {
+ this.$selectAll.prop('disabled', false);
+ this.$selectAll.prop('checked', this.selectedFiles().length == this.visibleFiles().length);
+ }
+ else {
+ this.$selectAll.prop('disabled', true);
+ this.$selectAll.prop('checked', false);
+ }
+ },
+
+ clearSelection: function() {
+ _.each(this.visibleFiles(), function(item) {
+ item.set('checked', false);
+ });
+ },
+
+ 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 (response) {
+ $btn.button('reset');
+
+ if (is_active)
+ locations.removeOption(data.host + '/' + data.path);
+ else
+ locations.addOption(response);
+ }).fail(function() {
+ $btn.button('reset');
+ $btn.button('toggle');
+
+ console.error(arguments);
+ });
+ },
+
+ initialLoad: function() {
+ var opts = this.hostSelectize.options,
+ location = localStorage.last_location || opts[Object.keys(opts)[0]].value;
+
+ this.router.navigate('#' + location, {trigger: true, replace: true});
+ },
+
+ 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();