Project

General

Profile

Defect #17071 » 0001-Multiple-Watcher-Selection-Patch.patch

Patch for Redmine 3.4.2 - Brett Patterson, 2017-08-25 16:43

View differences:

app/views/watchers/_new.html.erb
21 21
                 :project_id => @project) }')" %>
22 22
  <div id="users_for_watcher">
23
    <%= principals_check_box_tags('watcher[user_ids][]', users) %>
23
    <%= principals_check_box_tags('watchers[]', users) %>
24 24
  </div>
25
  <div id="users_watching_issue" style="display: none;"></div>
26
  <%= javascript_tag "var persistentWatcher = new persistWatchersList('watcher[user_ids][]', 'users_watching_issue', 'users_for_watcher');" %>
27
  <%= javascript_tag do -%>
28
      $(document).ajaxSuccess(function (evt, xhr, settings ) {
29
        if (/^\/watchers\/autocomplete_for_user\?/.test(settings.url)) {
30
            persistentWatcher.bindCheckboxes();
31
        }
32
      });
33
  <% end -%>
25 34
  <p class="buttons">
26 35
    <%= 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
796 796
  }
797 797
}
798
function persistWatchersList(inputName, inputContainer, checkboxContainer) {
799
    this.inputName = inputName;
800
    this.inputContainer = $('#' + inputContainer);
801
    this.checkboxContainer = $('#' + checkboxContainer);
802
    this.bindCheckboxes();
803
}
804

  
805
persistWatchersList.prototype = {
806
    bindCheckboxes: function () {
807
        var oThis = this;
808
        this.checkboxContainer.find("input[type='checkbox']").each(function (idx) {
809
            var checkbox = $(this);
810
            oThis.inputContainer.find("input[type='hidden']").each(function (index) {
811
                if ($(this).val() == checkbox.val()) {
812
                    checkbox.prop('checked', true);
813
                }
814
            });
815
            checkbox.change(function (evt) {
816
                oThis.watcherChange($(this));
817
            });
818
        });
819
    },
820

  
821
    watcherChange: function (input) {
822
        if (input.is(':checked')) {
823
            this.inputContainer.append(
824
                '<input type="hidden" name="' + this.inputName + '" value="' + input.val() + '" />'
825
            );
826
        } else {
827
            this.inputContainer.find('input[name="' + this.inputName + '"][value="' + input.val() + '"]').remove();
828
        }
829
    }
830
};
831

  
832

  
798 833
(function ( $ ) {
799 834
  // detect if native date input is supported
(2-2/3)