public_html/layouts/basic/components/MediaModal.min.js
'use strict';
/* {[The file is published on the basis of YetiForce Public License 6.5 that can be found in the following directory: licenses/LicenseEN.txt or yetiforce.com]} */"use strict";function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o},_typeof(o)}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError("Cannot call a class as a function")}function _defineProperties(target,props){for(var descriptor,i=0;i<props.length;i++)descriptor=props[i],descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,"value"in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,_toPropertyKey(descriptor.key),descriptor);}function _createClass(Constructor,protoProps,staticProps){return protoProps&&_defineProperties(Constructor.prototype,protoProps),staticProps&&_defineProperties(Constructor,staticProps),Object.defineProperty(Constructor,"prototype",{writable:!1}),Constructor}function _toPropertyKey(arg){var key=_toPrimitive(arg,"string");return "symbol"===_typeof(key)?key:String(key)}function _toPrimitive(input,hint){if("object"!==_typeof(input)||null===input)return input;var prim=input[Symbol.toPrimitive];if(prim!==void 0){var res=prim.call(input,hint||"default");if("object"!==_typeof(res))return res;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===hint?String:Number)(input)}window.AppComponents_MediaModal_Js=/*#__PURE__*/function(){function _class(){_classCallCheck(this,_class);}return _createClass(_class,[{key:"setPage",value:/**
* Set page
* @param {int} page
*/function setPage(){var page=0<arguments.length&&void 0!==arguments[0]?arguments[0]:1,min=(page-1)*this.pageLimit,max=page*this.pageLimit,tab=this.getActiveTab(),elements=tab.find(".js-icon-item:not(.not-match)");tab.find(".js-icon-item").addClass("d-none"),elements.slice(min,max).removeClass("d-none"),this.container.find(".js-page--set").data("id",page).find(".page-link").text(page),elements.eq(max+1).length?this.container.find(".js-page--next,.js-page--last").removeClass("disabled"):this.container.find(".js-page--next,.js-page--last").addClass("disabled"),0!==min&&elements.eq(min-1).length?this.container.find(".js-page--previous,.js-page--first").removeClass("disabled"):this.container.find(".js-page--previous,.js-page--first").addClass("disabled");}/**
* Get active tab
* @returns
*/},{key:"getActiveTab",value:function getActiveTab(){return this.container.find(".js-tab.active")}/**
* Register pagination events
*/},{key:"registerPaginationEvents",value:function registerPaginationEvents(){var _this=this;this.container.on("click",".js-page--next:not(.disabled)",function(){var currentPage=_this.container.find(".js-page--set.active").data("id");_this.setPage(parseInt(currentPage)+1);}),this.container.on("click",".js-page--previous:not(.disabled)",function(){var currentPage=_this.container.find(".js-page--set.active").data("id");1!==currentPage&&_this.setPage(currentPage-1);}),this.container.on("click",".js-page--first:not(.disabled)",function(){_this.setPage(1);}),this.container.on("click",".js-page--last:not(.disabled)",function(){var elements=_this.container.find(".js-icon-item:not(.not-match)"),totalPages=Math.ceil(elements.length/_this.pageLimit);_this.setPage(totalPages);});}/**
* Register Icon Search
*/},{key:"registerSearchIcon",value:function registerSearchIcon(){var _this2=this;this.searchField.on("keyup",function(e){var tab=_this2.getActiveTab();tab.find(".js-icon-item.not-match").removeClass("not-match");var value=e.currentTarget.value.toString().replace("\"","").toLowerCase();value.length&&tab.find(".js-icon-item:not([data-icon-search*=\"".concat(value,"\"])")).addClass("not-match"),_this2.setPage(1);});}/**
* Remove image item
* @param {Event} e
*/},{key:"removeItem",value:function removeItem(e){var url=e.currentTarget.dataset.url,progressIndicatorElement=$.progressIndicator({position:"html",blockInfo:{enabled:!0}});AppConnector.request({async:!1,url:url,type:"POST",data:{}}).done(function(data){data.result&&e.currentTarget.closest(".js-icon-item").remove(),progressIndicatorElement.progressIndicator({mode:"hide"});}).fail(function(error,err){progressIndicatorElement.progressIndicator({mode:"hide"}),app.errorLog(error,err);});}},{key:"registerImageEvents",value:function registerImageEvents(){var _this3=this,fileInput=this.container.find(".js-icon-file");if(fileInput.length){var fieldInfo=fileInput.data("fieldinfo")||{};this.container.find(".js-image-add").on("click",function(){fileInput.trigger("click");});var file=App.File.register(fileInput,{fileupload:{dataType:"json",replaceFileInput:!1,autoUpload:!1,done:function done(e,data){var attach=data.result.result.attach;attach.forEach(function(fileAttach){return "undefined"==typeof fileAttach.key?file.uploadError(e,data):void(file.filesActive--,_this3.addImage(fileAttach))}),file.fileInput.val("");}},formats:fieldInfo.formats,limit:fieldInfo.limit,maxFileSize:fieldInfo.maxFileSize,maxFileSizeDisplay:fieldInfo.maxFileSizeDisplay||""});}this.container.find(".js-image-remove").on("click",function(e){e.stopPropagation(),app.showConfirmModal({text:app.vtranslate("JS_LBL_ARE_YOU_SURE_YOU_WANT_TO_DELETE"),confirmedCallback:function confirmedCallback(){_this3.removeItem(e);}});});}/**
* Add image to container
* @param {Object} data
*/},{key:"addImage",value:function addImage(data){var item=document.createElement("article");item.setAttribute("class","w-100 position-relative js-icon-item"),item.setAttribute("data-icon-search",data.name.toLowerCase()),item.setAttribute("data-name",data.name),item.setAttribute("data-type","image"),item.setAttribute("data-src",data.src),item.setAttribute("data-key",data.key);var button=document.createElement("button");button.setAttribute("class","btn btn-light w-100 h-100");var image=document.createElement("img");image.setAttribute("class","icon-img--list"),image.setAttribute("src",data.src);var span=document.createElement("span");span.setAttribute("class","c-grid-item--signature u-fs-xs"),span.appendChild(document.createTextNode(data.name)),button.appendChild(image),button.appendChild(span),item.appendChild(button),this.getActiveTab().find("#icons-results").append(item);}/**
* Register events
*/},{key:"registerEvents",value:function registerEvents(container){var _this4=this;this.container=container,this.pageLimit=parseInt(this.container.find(".js-page-size").val()),this.searchField=this.container.find(".js-icon-search"),this.setPage(),this.registerPaginationEvents(),this.registerSearchIcon(),this.container.on("shown.bs.tab","a[data-toggle=\"tab\"]",function(){_this4.searchField.trigger("keyup");}),this.registerImageEvents();}}]),_class}();
//# sourceMappingURL=MediaModal.min.js.map