diff --git a/app/views/watchers/_new.html.erb b/app/views/watchers/_new.html.erb index 6282d59aa0da7b122c10cc484165ebcfd29e1888..311fbe4c1732486c74b87b1ddf9422905472b5c3 100644 --- a/app/views/watchers/_new.html.erb +++ b/app/views/watchers/_new.html.erb @@ -17,8 +17,18 @@ :project_id => @project) }')" %>
- <%= principals_check_box_tags('watcher[user_ids][]', users) %> + <%= principals_check_box_tags('watchers[]', users) %>
+ + <%= javascript_tag "var persistentWatcher = new persistWatchersList('watcher[user_ids][]', 'users_watching_issue', 'users_for_watcher');" %> + <%= javascript_tag do -%> + $(document).ajaxSuccess(function (evt, xhr, settings ) { + if (/^\/watchers\/autocomplete_for_user\?/.test(settings.url)) { + persistentWatcher.bindCheckboxes(); + } + }); + <% end -%> +

<%= submit_tag l(:button_add), :name => nil, :onclick => "hideModal(this);" %> diff --git a/app/views/watchers/autocomplete_for_user.html.erb b/app/views/watchers/autocomplete_for_user.html.erb index a24d28eb46d52c44119ea1799ad3848c9941197f..ea744fe84504ca1b04070408c0a2f96281ab959a 100644 --- a/app/views/watchers/autocomplete_for_user.html.erb +++ b/app/views/watchers/autocomplete_for_user.html.erb @@ -1 +1 @@ -<%= principals_check_box_tags 'watcher[user_ids][]', @users %> +<%= principals_check_box_tags 'watchers[]', @users %> diff --git a/public/javascripts/application.js b/public/javascripts/application.js index fdf5c477bb20c345bc661d75d4cc178290074b11..b8b68c565ead8889858f376c939ef69452f66016 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -602,6 +602,40 @@ function toggleDisabledOnChange() { function toggleDisabledInit() { $('input[data-disables], input[data-enables]').each(toggleDisabledOnChange); } + +function persistWatchersList(inputName, inputContainer, checkboxContainer) { + this.inputName = inputName; + this.inputContainer = $('#' + inputContainer); + this.checkboxContainer = $('#' + checkboxContainer); + + this.bindCheckboxes(); +} + +persistWatchersList.prototype = { + bindCheckboxes: function () { + var oThis = this; + this.checkboxContainer.find("input[type='checkbox']").each(function(idx) { + var checkbox = $(this); + oThis.inputContainer.find("input[type='hidden']").each(function (index) { + if ($(this).val() == checkbox.val()) { + checkbox.prop('checked', true); + } + }); + checkbox.change(function (evt) { oThis.watcherChange($(this)); }); + }); + }, + + watcherChange: function(input) { + if (input.is(':checked')) { + this.inputContainer.append( + '' + ); + } else { + this.inputContainer.find('input[name="' + this.inputName + '"][value="' + input.val() + '"]').remove(); + } + } +} + $(document).ready(function(){ $('#content').on('change', 'input[data-disables], input[data-enables]', toggleDisabledOnChange); toggleDisabledInit();