MDL-65254 core_message: Fix going back to message view drawer search
[moodle.git] / message / amd / build / message_drawer_view_search.min.js
CommitLineData
3118db5d 1define(["jquery","core/custom_interaction_events","core/notification","core/pubsub","core/str","core/templates","core_message/message_repository","core_message/message_drawer_events"],function(a,b,c,d,e,f,g,h){var i=50,j=50,k=3,l={BLOCK_ICON_CONTAINER:'[data-region="block-icon-container"]',CANCEL_SEARCH_BUTTON:'[data-action="cancel-search"]',CONTACTS_CONTAINER:'[data-region="contacts-container"]',CONTACTS_LIST:'[data-region="contacts-container"] [data-region="list"]',EMPTY_MESSAGE_CONTAINER:'[data-region="empty-message-container"]',LIST:'[data-region="list"]',LOADING_ICON_CONTAINER:'[data-region="loading-icon-container"]',LOADING_PLACEHOLDER:'[data-region="loading-placeholder"]',MESSAGES_LIST:'[data-region="messages-container"] [data-region="list"]',MESSAGES_CONTAINER:'[data-region="messages-container"]',NON_CONTACTS_CONTAINER:'[data-region="non-contacts-container"]',NON_CONTACTS_LIST:'[data-region="non-contacts-container"] [data-region="list"]',SEARCH_ICON_CONTAINER:'[data-region="search-icon-container"]',SEARCH_ACTION:'[data-action="search"]',SEARCH_INPUT:'[data-region="search-input"]',SEARCH_RESULTS_CONTAINER:'[data-region="search-results-container"]',LOAD_MORE_USERS:'[data-action="load-more-users"]',LOAD_MORE_MESSAGES:'[data-action="load-more-messages"]',BUTTON_TEXT:'[data-region="button-text"]',NO_RESULTS_CONTAINTER:'[data-region="no-results-container"]',ALL_CONTACTS_CONTAINER:'[data-region="all-contacts-container"]'},m={CONTACTS_LIST:"core_message/message_drawer_contacts_list",NON_CONTACTS_LIST:"core_message/message_drawer_non_contacts_list",MESSAGES_LIST:"core_message/message_drawer_messages_list"},n=function(a){return a.attr("data-user-id")},o=function(a){return a.find(l.EMPTY_MESSAGE_CONTAINER)},p=function(a){return a.find(l.LOADING_ICON_CONTAINER)},q=function(a){return a.find(l.LOADING_PLACEHOLDER)},r=function(a){return a.find(l.SEARCH_ICON_CONTAINER)},s=function(a){return a.find(l.SEARCH_INPUT)},t=function(a){return a.find(l.SEARCH_RESULTS_CONTAINER)},u=function(a){return a.find(l.CONTACTS_CONTAINER)},v=function(a){return a.find(l.NON_CONTACTS_CONTAINER)},w=function(a){return a.find(l.MESSAGES_CONTAINER)},x=function(a){o(a).removeClass("hidden")},y=function(a){o(a).addClass("hidden")},z=function(a){p(a).removeClass("hidden")},A=function(a){p(a).addClass("hidden")},B=function(a){q(a).removeClass("hidden")},C=function(a){q(a).addClass("hidden")},D=function(a){r(a).removeClass("hidden")},E=function(a){r(a).addClass("hidden")},F=function(a){t(a).removeClass("hidden")},G=function(a){t(a).addClass("hidden")},H=function(a){var b=t(a);b.find(l.ALL_CONTACTS_CONTAINER).addClass("hidden"),b.find(l.MESSAGES_CONTAINER).addClass("hidden"),b.find(l.NO_RESULTS_CONTAINTER).removeClass("hidden")},I=function(a){var b=t(a);b.find(l.ALL_CONTACTS_CONTAINER).removeClass("hidden"),b.find(l.MESSAGES_CONTAINER).removeClass("hidden"),b.find(l.NO_RESULTS_CONTAINTER).addClass("hidden")},J=function(a){var b=t(a);b.find(l.ALL_CONTACTS_CONTAINER).removeClass("hidden")},K=function(a){var b=t(a);b.find(l.ALL_CONTACTS_CONTAINER).addClass("hidden")},L=function(a){var b=t(a);b.find(l.CONTACTS_CONTAINER).removeClass("hidden")},M=function(a){var b=t(a);b.find(l.CONTACTS_CONTAINER).addClass("hidden")},N=function(a){var b=t(a);b.find(l.NON_CONTACTS_CONTAINER).removeClass("hidden")},O=function(a){var b=t(a);b.find(l.NON_CONTACTS_CONTAINER).addClass("hidden")},P=function(a){var b=t(a);b.find(l.MESSAGES_CONTAINER).removeClass("hidden")},Q=function(a){var b=t(a);b.find(l.MESSAGES_CONTAINER).addClass("hidden")},R=function(a){s(a).prop("disabled",!0)},S=function(a){s(a).prop("disabled",!1)},T=function(a){s(a).val("")},U=function(a){a.find(l.CONTACTS_LIST).empty(),a.find(l.NON_CONTACTS_LIST).empty(),a.find(l.MESSAGES_LIST).empty(),I(a),J(a),L(a),N(a),P(a),Z(a),ba(a)},V=function(a,b){E(a),y(b),G(b),z(a),B(b),R(a)},W=function(a,b){D(a),y(b),F(b),A(a),C(b),S(a)},X=function(a){var b=a.find(l.LOAD_MORE_USERS);b.prop("disabled",!0),b.find(l.BUTTON_TEXT).addClass("hidden"),b.find(l.LOADING_ICON_CONTAINER).removeClass("hidden")},Y=function(a){var b=a.find(l.LOAD_MORE_USERS);b.prop("disabled",!1),b.find(l.BUTTON_TEXT).removeClass("hidden"),b.find(l.LOADING_ICON_CONTAINER).addClass("hidden")},Z=function(a){a.find(l.LOAD_MORE_USERS).removeClass("hidden")},$=function(a){a.find(l.LOAD_MORE_USERS).addClass("hidden")},_=function(a){var b=a.find(l.LOAD_MORE_MESSAGES);b.prop("disabled",!0),b.find(l.BUTTON_TEXT).addClass("hidden"),b.find(l.LOADING_ICON_CONTAINER).removeClass("hidden")},aa=function(a){var b=a.find(l.LOAD_MORE_MESSAGES);b.prop("disabled",!1),b.find(l.BUTTON_TEXT).removeClass("hidden"),b.find(l.LOADING_ICON_CONTAINER).addClass("hidden")},ba=function(a){a.find(l.LOAD_MORE_MESSAGES).removeClass("hidden")},ca=function(a){a.find(l.LOAD_MORE_MESSAGES).addClass("hidden")},da=function(a,b){return a.find('[data-contact-user-id="'+b+'"]')},ea=function(a,b){var c=v(a),d=da(c,b.userid);if(d.length){d.remove();var e=u(a);e.removeClass("hidden"),e.find(l.LIST).append(d)}c.find(l.LIST).children().length||c.addClass("hidden")},fa=function(a,b){var c=u(a),d=da(c,b);if(d.length){d.remove();var e=v(a);e.removeClass("hidden"),e.find(l.LIST).append(d)}c.find(l.LIST).children().length||c.addClass("hidden")},ga=function(a,b){var c=da(a,b);c.length&&c.find(l.BLOCK_ICON_CONTAINER).removeClass("hidden")},ha=function(a,b){var c=da(a,b);c.length&&c.find(l.BLOCK_ICON_CONTAINER).addClass("hidden")},ia=function(a,b){var c=u(a),d=c.find(l.LIST);return f.render(m.CONTACTS_LIST,{contacts:b}).then(function(a){return d.append(a),a})},ja=function(a,b){var c=v(a),d=c.find(l.LIST);return f.render(m.NON_CONTACTS_LIST,{noncontacts:b}).then(function(a){return d.append(a),a})},ka=function(a,b){var c=w(a),d=c.find(l.LIST);return f.render(m.MESSAGES_LIST,{messages:b}).then(function(a){return d.append(a),a})},la=function(b,c,d,e,f){var h=!1;return X(b),g.searchUsers(c,d,e+1,f).then(function(a){var b=a.contacts,c=a.noncontacts;return b.length<=e&&c.length<=e?(h=!0,{contacts:b,noncontacts:c}):{contacts:b.slice(0,e),noncontacts:c.slice(0,e)}}).then(function(c){var d=c.contacts.length,e=c.noncontacts.length;return a.when(!d||ia(b,c.contacts),!e||ja(b,c.noncontacts)).then(function(){return{contactsCount:d,nonContactsCount:e}})}).then(function(a){return Y(b),h&&$(b),a})["catch"](function(a){throw Y(b),a})},ma=function(a,b,c,d,e){var f=!1;return _(a),g.searchMessages(b,c,d+1,e).then(function(a){var b=a.contacts;return b.length<=d?(f=!0,b):b.slice(0,d)}).then(function(b){return b.length?ka(a,b).then(function(){return b.length}):b.length}).then(function(b){return aa(a),f&&ca(a),b})["catch"](function(b){throw aa(a),b})},na=function(b,c,d,e,f,g,h){var i=n(c);return V(b,c),U(c),a.when(la(c,i,d,e,f),ma(c,i,d,g,h)).then(function(a,d){var e=a.contactsCount,f=a.nonContactsCount;W(b,c),e||f||d?(e||f?(e||M(c),f||O(c)):K(c),d||Q(c)):H(c)})},oa=function(a,e){var f=n(e),g=s(a),m="",o=0,p=0,q=function(b,d){m=g.val().trim(),""!==m&&(o=0,p=0,na(a,e,m,k,p,i,o).then(function(){g.focus(),p+=k,o+=i})["catch"](c.exception)),d.originalEvent.preventDefault()};b.define(g,[b.events.enter]),b.define(a,[b.events.activate]),b.define(e,[b.events.activate]),g.on(b.events.enter,q),a.on(b.events.activate,l.SEARCH_ACTION,q),e.on(b.events.activate,l.LOAD_MORE_MESSAGES,function(a,b){""!==m&&ma(e,f,m,i,o).then(function(){o+=i})["catch"](c.exception),b.originalEvent.preventDefault()}),e.on(b.events.activate,l.LOAD_MORE_USERS,function(a,b){""!==m&&la(e,f,m,j,p).then(function(){p+=j})["catch"](c.exception),b.originalEvent.preventDefault()}),a.on(b.events.activate,l.CANCEL_SEARCH_BUTTON,function(){T(a),x(e),D(a),G(e),A(a),C(e),p=0,o=0}),d.subscribe(h.CONTACT_ADDED,function(a){ea(e,a)}),d.subscribe(h.CONTACT_REMOVED,function(a){fa(e,a)}),d.subscribe(h.CONTACT_BLOCKED,function(a){ga(e,a)}),d.subscribe(h.CONTACT_UNBLOCKED,function(a){ha(e,a)})},pa=function(b,c,d){d.attr("data-init")||(oa(c,d),d.attr("data-init",!0));var e=s(c);return e.focus(),a.Deferred().resolve().promise()},qa=function(a,b){var c=s(b),d=c.val().trim();return e.get_string("messagedrawerviewsearch","core_message",d)};return{show:pa,description:qa}});