From f505883e452f3c1e2653096f57e3494e0546fc46 Mon Sep 17 00:00:00 2001 From: Robin McCorkell Date: Wed, 12 Aug 2015 22:01:21 +0100 Subject: Add on-backend and on-auth-mechanism events to JS --- apps/files_external/js/settings.js | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/apps/files_external/js/settings.js b/apps/files_external/js/settings.js index d3e20e38445..b542fe63d64 100644 --- a/apps/files_external/js/settings.js +++ b/apps/files_external/js/settings.js @@ -550,7 +550,7 @@ var MountConfigListView = function($el, options) { /** * @memberOf OCA.External.Settings */ -MountConfigListView.prototype = { +MountConfigListView.prototype = _.extend({ /** * jQuery element containing the config list @@ -644,11 +644,31 @@ MountConfigListView.prototype = { addSelect2(this.$el.find('tr:not(#addMountPoint) .applicableUsers'), this._userListLimit); - this.$el.find('tr:not(#addMountPoint)').each(function(i, tr) { + this._initEvents(); + + this.$el.find('tbody tr:not(#addMountPoint)').each(function(i, tr) { self.recheckStorageConfig($(tr)); }); + }, - this._initEvents(); + /** + * Custom JS event handlers + * Trigger callback for all existing configurations + */ + whenSelectBackend: function(callback) { + this.$el.find('tbody tr:not(#addMountPoint)').each(function(i, tr) { + var backend = $(tr).find('.backend').data('class'); + callback($(tr), backend); + }); + this.on('selectBackend', callback); + }, + whenSelectAuthMechanism: function(callback) { + var self = this; + this.$el.find('tbody tr:not(#addMountPoint)').each(function(i, tr) { + var authMechanism = $(tr).find('.selectAuthMechanism').val(); + callback($(tr), authMechanism, self._allAuthMechanisms[authMechanism]['scheme']); + }); + this.on('selectAuthMechanism', callback); }, /** @@ -728,6 +748,8 @@ MountConfigListView.prototype = { var $td = $tr.find('td.configuration'); $.each(backendConfiguration['configuration'], _.partial(this.writeParameterInput, $td)); + this.trigger('selectBackend', $tr, backend); + selectAuthMechanism.trigger('change'); // generate configuration parameters for auth mechanism var priorityEl = $(''); @@ -758,6 +780,10 @@ MountConfigListView.prototype = { this.writeParameterInput, $td, _, _, ['auth-param'] )); + this.trigger('selectAuthMechanism', + $tr, authMechanism, authMechanismConfiguration['scheme'] + ); + if ($tr.data('constructing') !== true) { // row is ready, trigger recheck this.saveStorageConfig($tr); @@ -1045,7 +1071,7 @@ MountConfigListView.prototype = { self.saveStorageConfig($tr); }); } -}; +}, OC.Backbone.Events); $(document).ready(function() { var enabled = $('#files_external').attr('data-encryption-enabled'); -- cgit v1.2.3