Created
July 12, 2016 09:15
-
-
Save hyperNURb/dd2c7f943f4611f3f114f0fd6c8a5a19 to your computer and use it in GitHub Desktop.
Revisions
-
hyperNURb created this gist
Jul 12, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,88 @@ diff --git a/src/ggrc/assets/javascripts/components/people_list.js b/src/ggrc/assets/javascripts/components/people_list.js index 20685e1..3b880c9 100644 --- a/src/ggrc/assets/javascripts/components/people_list.js +++ b/src/ggrc/assets/javascripts/components/people_list.js @@ -444,7 +444,6 @@ var instance = scope.attr('instance'); var deferred = scope.attr('deferred'); var relationship; - var $personElement; if (deferred) { this.scope.deferred_add_role(person, role); @@ -464,41 +463,36 @@ relationship = relationship.refresh(); } + this.scope.attr('isLoading', true); relationship.done(function (relationship) { var type = relationship.attr('attrs.AssigneeType'); relationship.attr('attrs.AssigneeType', role + (type ? ',' + type : '')); relationship.save() .then(function (rel) { - var instanceDfd = $.Deferred(); - var personDfd = $.Deferred(); - function checkRelationship(related, id) { - return _.findWhere(related, {id: id}); - } - function onInstanceChange() { - if (checkRelationship(this.related_sources, rel.id)) { - instance.unbind('change', onInstanceChange); - instanceDfd.resolve(); - } - } - function onPersonChange() { - if (checkRelationship(this.related_destinations, rel.id)) { - person.unbind('change', onPersonChange); - personDfd.resolve(); - } - } - $personElement = $(el).closest('ul') - .find('[data-person=' + person.id + ']').parent(); - $personElement.hide(); - instance.on('change', onInstanceChange); - person.on('change', onPersonChange); - return $.when(instanceDfd, personDfd); + var props = ['related_destinations', 'related_sources']; + var dfds = []; + + ['source', 'destination'].forEach(function (type) { + var obj = rel[type]; + var model = CMS.Models[obj.type].findInCacheById(obj.id); + var dfd = $.Deferred(); + + props.forEach(function (prop) { + model[prop].on('change', dfd.resolve); + dfd.done(function () { + model[prop].unbind('change', dfd.resolve); + }); + dfds.push(dfd); + }); + }); + return $.when.apply($, dfds); }) .then(function () { - $personElement.show(); - }) - .then(instance.refresh); - }); + this.scope.attr('isLoading', false); + instance.refresh(); + }.bind(this)); + }.bind(this)); } }, 'modal:success': function () { @@ -518,7 +512,11 @@ can_unmap: function (options) { var results = this.attr('results'); var required = this.attr('required'); + var isLoading = this.attr('isLoading'); + if (isLoading) { + return options.inverse(options.context); + } if (required) { if (results.length > 1) { return options.fn(options.context);