text: sap.ui.define(["com/owi/webmin/weblogCrud/controller/BaseController","sap/ui/model/json/JSONModel","sap/ui/model/Filter","sap/ui/model/FilterOperator","sap/m/GroupHeaderListItem","sap/ui/Device","com/owi/webmin/weblogCrud/model/formatter","sap/m/MessageBox","com/owi/webmin/weblogCrud/model/grouper","com/owi/webmin/weblogCrud/model/GroupSortState"],function(e,t,i,o,s,r,n,a,l,h){"use strict";return e.extend("com.owi.webmin.weblogCrud.controller.Master",{formatter:n,onInit:function(){var e=this.byId("list"),t=this._createViewModel(),i=e.getBusyIndicatorDelay();this._oListSelector=this.getOwnerComponent().oListSelector;this._oGroupSortState=new h(t,l.groupUnitNumber(this.getResourceBundle()));this._oList=e;this._oListFilterState={aFilter:[],aSearch:[]};this.setModel(t,"masterView");e.attachEventOnce("updateFinished",function(){t.setProperty("/delay",i)});this.getView().addEventDelegate({onBeforeFirstShow:function(){this._oListSelector.setBoundMasterList(e)}.bind(this)});this.getRouter().getRoute("master").attachPatternMatched(this._onMasterMatched,this);this.getRouter().attachBypassed(this.onBypassed,this);this._oODataModel=this.getOwnerComponent().getModel()},onUpdateFinished:function(e){this._updateListItemCount(e.getParameter("total"));this.byId("pullToRefresh").hide();this._findItem();this.getModel("appView").setProperty("/addEnabled",true)},onSearch:function(e){if(e.getParameters().refreshButtonPressed){this.onRefresh();return}var t=e.getParameter("query");if(t){this._oListFilterState.aSearch=[new i("KEYTYPE",o.Contains,t)]}else{this._oListFilterState.aSearch=[]}this._applyFilterSearch()},onRefresh:function(){this._oList.getBinding("items").refresh()},onSort:function(e){var t=e.getSource().getSelectedItem().getKey(),i=this._oGroupSortState.sort(t);this._applyGroupSort(i)},onGroup:function(e){var t=e.getSource().getSelectedItem().getKey(),i=this._oGroupSortState.group(t);this._applyGroupSort(i)},onOpenViewSettings:function(){if(!this._oViewSettingsDialog){this._oViewSettingsDialog=sap.ui.xmlfragment("com.owi.webmin.weblogCrud.view.ViewSettingsDialog",this);this.getView().addDependent(this._oViewSettingsDialog);this._oViewSettingsDialog.addStyleClass(this.getOwnerComponent().getContentDensityClass())}this._oViewSettingsDialog.open()},onConfirmViewSettingsDialog:function(e){var t=e.getParameters().filterItems,s=[],r=[];t.forEach(function(e){switch(e.getKey()){case"Filter1":s.push(new i("KEYID",o.LE,100));break;case"Filter2":s.push(new i("KEYID",o.GT,100));break;default:break}r.push(e.getText())});this._oListFilterState.aFilter=s;this._updateFilterBar(r.join(", "));this._applyFilterSearch()},onSelectionChange:function(e){var t=this;var i=e.getParameter("listItem")||e.getSource();var o=function(){t._oODataModel.resetChanges();t._showDetail(i)};if(this._oODataModel.hasPendingChanges()){this._leaveEditPage(o)}else{this._showDetail(i)}t.getModel("appView").setProperty("/addEnabled",true)},onBypassed:function(){this._oList.removeSelections(true)},createGroupHeader:function(e){return new s({title:e.text,upperCase:false})},onNavBack:function(){var e=sap.ui.core.routing.History.getInstance(),t=e.getPreviousHash(),i=sap.ushell.Container.getService("CrossApplicationNavigation");if(t!==undefined){history.go(-1)}else{i.toExternal({target:{shellHash:"#Shell-home"}})}},onAdd:function(){this.getModel("appView").setProperty("/addEnabled",false);this.getRouter().getTargets().display("create")},_createViewModel:function(){return new t({isFilterBarVisible:false,filterBarLabel:"",delay:0,title:this.getResourceBundle().getText("masterTitleCount",[0]),noDataText:this.getResourceBundle().getText("masterListNoDataText"),sortBy:"KEYTYPE",groupBy:"None"})},_leaveEditPage:function(e,t){var i=this.getResourceBundle().getText("warningConfirm");var o=this.getResourceBundle().getText("warning");a.show(i,{icon:a.Icon.WARNING,title:o,actions:[a.Action.OK,a.Action.CANCEL],onClose:function(i){if(i===a.Action.OK){e()}else if(t){t()}}})},_onMasterMatched:function(){this._oListSelector.oWhenListLoadingIsDone.then(function(e){if(e.list.getMode()==="None"){return}this.getModel("appView").setProperty("/addEnabled",true);if(!e.list.getSelectedItem()){this.getRouter().navTo("object",{ROWID:encodeURIComponent(e.firstListitem.getBindingContext().getProperty("ROWID"))},true)}}.bind(this),function(e){if(e.error){return}this.getRouter().getTargets().display("detailNoObjectsAvailable")}.bind(this))},_showDetail:function(e){var t=!r.system.phone;this.getRouter().navTo("object",{ROWID:encodeURIComponent(e.getBindingContext().getProperty("ROWID"))},t)},_updateListItemCount:function(e){var t;if(this._oList.getBinding("items").isLengthFinal()){t=this.getResourceBundle().getText("masterTitleCount",[e]);this.getModel("masterView").setProperty("/title",t)}},_applyFilterSearch:function(){var e=this._oListFilterState.aSearch.concat(this._oListFilterState.aFilter),t=this.getModel("masterView");this._oList.getBinding("items").filter(e,"Application");if(e.length!==0){t.setProperty("/noDataText",this.getResourceBundle().getText("masterListNoDataWithFilterOrSearchText"))}else if(this._oListFilterState.aSearch.length>0){t.setProperty("/noDataText",this.getResourceBundle().getText("masterListNoDataText"))}},_applyGroupSort:function(e){this._oList.getBinding("items").sort(e)},_updateFilterBar:function(e){var t=this.getModel("masterView");t.setProperty("/isFilterBarVisible",this._oListFilterState.aFilter.length>0);t.setProperty("/filterBarLabel",this.getResourceBundle().getText("masterFilterBarText",[e]))},_fnGetPathWithSlash:function(e){return(e.indexOf("/")===0?"":"/")+e},_findItem:function(){var e=this.getModel("appView").getProperty("/itemToSelect");if(e){var t=this._fnGetPathWithSlash(e);var i=this._oListSelector.findListItem(t);if(!i){i=this._oListSelector.findFirstItem();if(i){t=i.getBindingContext().getPath()}else{this.getRouter().getTargets().display("detailNoObjectsAvailable");return}}this._oListSelector.selectAListItem(t);this._showDetail(i)}}})});