weekly release 4.0dev+
[moodle.git] / message / amd / build / message_drawer_view_search.min.js
CommitLineData
f879cc51 1function _typeof(a){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("core_message/message_drawer_view_search",["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=3,k={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\"]"},l={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"},m=function(a){return a.attr("data-user-id")},n=function(a){return a.find(k.EMPTY_MESSAGE_CONTAINER)},o=function(a){return a.find(k.LOADING_ICON_CONTAINER)},p=function(a){return a.find(k.LOADING_PLACEHOLDER)},q=function(a){return a.find(k.SEARCH_ICON_CONTAINER)},r=function(a){return a.find(k.SEARCH_INPUT)},s=function(a){return a.find(k.SEARCH_RESULTS_CONTAINER)},t=function(a){return a.find(k.CONTACTS_CONTAINER)},u=function(a){return a.find(k.NON_CONTACTS_CONTAINER)},v=function(a){return a.find(k.MESSAGES_CONTAINER)},w=function(a){n(a).removeClass("hidden")},x=function(a){n(a).addClass("hidden")},y=function(a){o(a).removeClass("hidden")},z=function(a){o(a).addClass("hidden")},A=function(a){p(a).removeClass("hidden")},B=function(a){p(a).addClass("hidden")},C=function(a){q(a).removeClass("hidden")},D=function(a){q(a).addClass("hidden")},E=function(a){s(a).removeClass("hidden")},F=function(a){s(a).addClass("hidden")},G=function(a){var b=s(a);b.find(k.ALL_CONTACTS_CONTAINER).addClass("hidden");b.find(k.MESSAGES_CONTAINER).addClass("hidden");b.find(k.NO_RESULTS_CONTAINTER).removeClass("hidden")},H=function(a){var b=s(a);b.find(k.ALL_CONTACTS_CONTAINER).removeClass("hidden");b.find(k.MESSAGES_CONTAINER).removeClass("hidden");b.find(k.NO_RESULTS_CONTAINTER).addClass("hidden")},I=function(a){var b=s(a);b.find(k.ALL_CONTACTS_CONTAINER).removeClass("hidden")},J=function(a){var b=s(a);b.find(k.ALL_CONTACTS_CONTAINER).addClass("hidden")},K=function(a){var b=s(a);b.find(k.CONTACTS_CONTAINER).removeClass("hidden")},L=function(a){var b=s(a);b.find(k.CONTACTS_CONTAINER).addClass("hidden")},M=function(a){var b=s(a);b.find(k.NON_CONTACTS_CONTAINER).removeClass("hidden")},N=function(a){var b=s(a);b.find(k.NON_CONTACTS_CONTAINER).addClass("hidden")},O=function(a){var b=s(a);b.find(k.MESSAGES_CONTAINER).removeClass("hidden")},P=function(a){var b=s(a);b.find(k.MESSAGES_CONTAINER).addClass("hidden")},Q=function(a){r(a).prop("disabled",!0)},R=function(a){r(a).prop("disabled",!1)},S=function(a){r(a).val("")},T=function(a){a.find(k.CONTACTS_LIST).empty();a.find(k.NON_CONTACTS_LIST).empty();a.find(k.MESSAGES_LIST).empty();H(a);I(a);K(a);M(a);O(a);Y(a);aa(a)},U=function(a,b){D(a);x(b);F(b);y(a);A(b);Q(a)},V=function(a,b){C(a);x(b);E(b);z(a);B(b);R(a)},W=function(a){var b=a.find(k.LOAD_MORE_USERS);b.prop("disabled",!0);b.find(k.BUTTON_TEXT).addClass("hidden");b.find(k.LOADING_ICON_CONTAINER).removeClass("hidden")},X=function(a){var b=a.find(k.LOAD_MORE_USERS);b.prop("disabled",!1);b.find(k.BUTTON_TEXT).removeClass("hidden");b.find(k.LOADING_ICON_CONTAINER).addClass("hidden")},Y=function(a){a.find(k.LOAD_MORE_USERS).removeClass("hidden")},Z=function(a){a.find(k.LOAD_MORE_USERS).addClass("hidden")},$=function(a){var b=a.find(k.LOAD_MORE_MESSAGES);b.prop("disabled",!0);b.find(k.BUTTON_TEXT).addClass("hidden");b.find(k.LOADING_ICON_CONTAINER).removeClass("hidden")},_=function(a){var b=a.find(k.LOAD_MORE_MESSAGES);b.prop("disabled",!1);b.find(k.BUTTON_TEXT).removeClass("hidden");b.find(k.LOADING_ICON_CONTAINER).addClass("hidden")},aa=function(a){a.find(k.LOAD_MORE_MESSAGES).removeClass("hidden")},ba=function(a){a.find(k.LOAD_MORE_MESSAGES).addClass("hidden")},ca=function(a,b){return a.find("[data-contact-user-id=\""+b+"\"]")},da=function(a,b){var c=u(a),d=ca(c,b.userid);if(d.length){d.remove();var e=t(a);e.removeClass("hidden");e.find(k.LIST).append(d)}if(!c.find(k.LIST).children().length){c.addClass("hidden")}},ea=function(a,b){var c=t(a),d=ca(c,b);if(d.length){d.remove();var e=u(a);e.removeClass("hidden");e.find(k.LIST).append(d)}if(!c.find(k.LIST).children().length){c.addClass("hidden")}},fa=function(a,b){var c=ca(a,b);if(c.length){c.find(k.BLOCK_ICON_CONTAINER).removeClass("hidden")}},ga=function(a,b){var c=ca(a,b);if(c.length){c.find(k.BLOCK_ICON_CONTAINER).addClass("hidden")}},ha=function(a,b){if(!a){return""}var c=new RegExp("("+b+")","gi");return a.replace(c,"<span class=\"matchtext\">$1</span>")},ia=function(a,b){var c=t(a),d=a.attr("data-in-panel"),e=c.find(k.LIST);return f.render(l.CONTACTS_LIST,{contacts:b,frompanel:d}).then(function(a){e.append(a);return a})},ja=function(a,b){var c=u(a),d=a.attr("data-in-panel"),e=c.find(k.LIST);return f.render(l.NON_CONTACTS_LIST,{noncontacts:b,frompanel:d}).then(function(a){e.append(a);return a})},ka=function(a,b){var c=v(a),d=a.attr("data-in-panel"),e=c.find(k.LIST);return f.render(l.MESSAGES_LIST,{messages:b,frompanel:d}).then(function(a){e.append(a);return a})},la=function(b,c,d,e,f){var h=!1;W(b);return g.searchUsers(c,d,e+1,f).then(function(a){var b=a.contacts,c=a.noncontacts;if(b.length<=e&&c.length<=e){h=!0;return{contacts:b,noncontacts:c}}else{return{contacts:b.slice(0,e),noncontacts:c.slice(0,e)}}}).then(function(c){var e=c.contacts.length,f=c.noncontacts.length;if(e){c.contacts.forEach(function(a){a.highlight=ha(a.fullname,d)})}if(f){c.noncontacts.forEach(function(a){a.highlight=ha(a.fullname,d)})}return a.when(e?ia(b,c.contacts):!0,f?ja(b,c.noncontacts):!0).then(function(){return{contactsCount:e,nonContactsCount:f}})}).then(function(a){X(b);if(h){Z(b)}return a}).catch(function(a){X(b);throw a})},ma=function(a,b,c,d,e){var f=!1;$(a);return g.searchMessages(b,c,d+1,e).then(function(a){var b=a.contacts;if(b.length<=d){f=!0;return b}else{return b.slice(0,d)}}).then(function(b){if(b.length){b.forEach(function(a){a.lastmessage=ha(a.lastmessage,c)});return ka(a,b).then(function(){return b.length})}else{return b.length}}).then(function(b){_(a);if(f){ba(a)}return b}).catch(function(b){_(a);throw b})},na=function(b,c,d,e,f,g,h){var i=m(c);U(b,c);T(c);return 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;V(b,c);if(!e&&!f&&!d){G(c)}else{if(!e&&!f){J(c)}else{if(!e){L(c)}if(!f){N(c)}}if(!d){P(c)}}})},oa=function(a,e){var f=m(e),g=r(a),l="",n=0,o=0,p=function(b,d){l=g.val().trim();if(""!==l){n=0;o=0;na(a,e,l,j,o,50,n).then(function(){g.focus();o=o+j;n=n+50}).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,p);a.on(b.events.activate,k.SEARCH_ACTION,p);e.on(b.events.activate,k.LOAD_MORE_MESSAGES,function(a,b){if(""!==l){ma(e,f,l,50,n).then(function(){n=n+50}).catch(c.exception)}b.originalEvent.preventDefault()});e.on(b.events.activate,k.LOAD_MORE_USERS,function(a,b){if(""!==l){la(e,f,l,i,o).then(function(){o=o+i}).catch(c.exception)}b.originalEvent.preventDefault()});a.on(b.events.activate,k.CANCEL_SEARCH_BUTTON,function(){S(a);w(e);C(a);F(e);z(a);B(e);o=0;n=0});d.subscribe(h.CONTACT_ADDED,function(a){da(e,a)});d.subscribe(h.CONTACT_REMOVED,function(a){ea(e,a)});d.subscribe(h.CONTACT_BLOCKED,function(a){fa(e,a)});d.subscribe(h.CONTACT_UNBLOCKED,function(a){ga(e,a)})},pa=function(a,b){if("object"!==_typeof(b)){return e.get_string("messagedrawerviewsearch","core_message")}var c=r(b),d=c.val().trim();return e.get_string("messagedrawerviewsearch","core_message",d)};return{show:function show(b,c,d){if(!d.attr("data-init")){oa(c,d);d.attr("data-init",!0)}var e=r(c);e.focus();return a.Deferred().resolve().promise()},description:pa}});
195ea448 2//# sourceMappingURL=message_drawer_view_search.min.js.map