Defect #17071 » patch_commit_6682c6d40dc8.patch
| app/views/watchers/_new.html.erb | ||
|---|---|---|
| 17 | 17 | :project_id => @project) }')" %> | 
| 18 | 18 | |
| 19 | 19 | <div id="users_for_watcher"> | 
| 20 |     <%= principals_check_box_tags('watcher[user_ids][]', users) %> | |
| 20 |     <%= principals_check_box_tags('watchers[]', users) %> | |
| 21 | 21 | </div> | 
| 22 | <div id="users_watching_issue" style="display: none;"></div> | |
| 23 |  <%= javascript_tag "var persistentWatcher = new persistWatchersList('watcher[user_ids][]', 'users_watching_issue', 'users_for_watcher');" %> | |
| 24 | <%= javascript_tag do -%> | |
| 25 |   	$(document).ajaxSuccess(function (evt, xhr, settings ) { | |
| 26 | 	  if (/^\/watchers\/autocomplete_for_user\?/.test(settings.url)) { | |
| 27 | persistentWatcher.bindCheckboxes(); | |
| 28 | } | |
| 29 | }); | |
| 30 | <% end -%> | |
| 31 | ||
| 22 | 32 | |
| 23 | 33 | <p class="buttons"> | 
| 24 | 34 | <%= submit_tag l(:button_add), :name => nil, :onclick => "hideModal(this);" %> | 
| app/views/watchers/autocomplete_for_user.html.erb | ||
|---|---|---|
| 1 | <%= principals_check_box_tags 'watcher[user_ids][]', @users %> | |
| 1 | <%= principals_check_box_tags 'watchers[]', @users %> | |
| public/javascripts/application.js | ||
|---|---|---|
| 602 | 602 | function toggleDisabledInit() { | 
| 603 | 603 |   $('input[data-disables], input[data-enables]').each(toggleDisabledOnChange); | 
| 604 | 604 | } | 
| 605 | ||
| 606 | function persistWatchersList(inputName, inputContainer, checkboxContainer) { | |
| 607 | this.inputName = inputName; | |
| 608 | 	this.inputContainer = $('#' + inputContainer); | |
| 609 | 	this.checkboxContainer = $('#' + checkboxContainer); | |
| 610 |  | |
| 611 | this.bindCheckboxes(); | |
| 612 | } | |
| 613 | ||
| 614 | persistWatchersList.prototype = { | |
| 615 | 	bindCheckboxes: function () { | |
| 616 | var oThis = this; | |
| 617 | 		this.checkboxContainer.find("input[type='checkbox']").each(function(idx) { | |
| 618 | var checkbox = $(this); | |
| 619 | 			oThis.inputContainer.find("input[type='hidden']").each(function (index) { | |
| 620 | 				if ($(this).val() == checkbox.val()) { | |
| 621 | 					checkbox.prop('checked', true); | |
| 622 | } | |
| 623 | }); | |
| 624 | 			checkbox.change(function (evt) { oThis.watcherChange($(this)); }); | |
| 625 | }); | |
| 626 | }, | |
| 627 |  | |
| 628 | 	watcherChange: function(input) { | |
| 629 | 		if (input.is(':checked')) { | |
| 630 | this.inputContainer.append( | |
| 631 | '<input type="hidden" name="' + this.inputName + '" value="' + input.val() + '" />' | |
| 632 | ); | |
| 633 | 		} else { | |
| 634 | 			this.inputContainer.find('input[name="' + this.inputName + '"][value="' + input.val() + '"]').remove(); | |
| 635 | } | |
| 636 | } | |
| 637 | } | |
| 638 | ||
| 605 | 639 | $(document).ready(function(){ | 
| 606 | 640 |   $('#content').on('change', 'input[data-disables], input[data-enables]', toggleDisabledOnChange); | 
| 607 | 641 | toggleDisabledInit(); |