<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<object-views xmlns="http://axelor.com/xml/ns/object-views"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://axelor.com/xml/ns/object-views http://axelor.com/xml/ns/object-views/object-views_5.2.xsd">
	
	<grid name="app-grid" title="Apps" model="com.axelor.apps.base.db.App" canDelete="false" canNew="false">
		<field name="name" />
		<field name="active" />
		<field name="demoDataLoaded" />
	</grid>
	
	<form name="app-form" title="App" model="com.axelor.apps.base.db.App" canDelete="false" canNew="false" width="large">
		<panel name="mainPanel">
			<field name="image" widget="Image" colSpan="2"/>
			<panel colSpan="6" name="infoPanel">
				<field name="name" readonly="true" colSpan="12" />
				<field name="languageSelect" selection-in="['en','fr']"/>
				<field name="demoDataLoaded" readonly="true" if="com.axelor.app.AppSettings.get().get('application.mode') != 'prod'"/>
			</panel>
			<field name="description" colSpan="12" readonly="true"/>
			<field name="initDataLoaded" hidden="true" />
			<field name="code" hidden="true" />
			<field name="active" hidden="true" />
			<field name="isRolesImported" hidden="true" />
		</panel>
		<panel itemSpan="12" sidebar="true" name="actionPanel">
				<button name="installBtn" title="Install"  onClick="action-app-alert-install,save,action-app-method-install-app"  showIf="!active" />
				<button name="uninstallBtn" title="Uninstall" onClick="action-app-alert-un-install,action-app-method-uninstall-app" showIf="active" />
				<button name="configureBtn" title="Configure" showIf="active" onClick="com.axelor.apps.base.web.AppController:configure" />
				<button name="importDataDemoBtn" if="com.axelor.app.AppSettings.get().get('application.mode') != 'prod'" showIf="active &amp;&amp; !demoDataLoaded" onClick="action-app-alert-demo-import,save,action-method-app-import-data-demo" title="Import demo data" />
				<button name="importRolesBtn" showIf="active &amp;&amp; !isRolesImported" onClick="save,action-app-method-import-roles" title="Import roles" />
		</panel>
		<panel-related name="dependsOnSetPanel" field="dependsOnSet" readonly="true" canSelect="false" canView="false" >
			<field name="name" />
			<field name="active"/>
		</panel-related>
	</form> 
	
	<form model="com.axelor.apps.base.db.App" title="Bulk install" name="bulk-install-app-form">
		<panel name="mainPanel">
			<button name="selectAllBtn" title="Select all" colSpan="4" onClick="action-app-bulk-install-select-all,action-app-bulk-install-apps-set-change"/>
			<field type="many-to-many" name="appsSet" target="com.axelor.apps.base.db.App" colSpan="12" title="Apps" canNew="false" domain="self.active = false or self.demoDataLoaded = false" height="200" onChange="action-app-bulk-install-apps-set-change"/>			
			<field name="languageSelect" type="string" selection="select.language" title="Language" colSpan="4" selection-in="['en','fr']"/>
			<field type="boolean" name="importDemoData" title="Import demo data" colSpan="3" if="com.axelor.app.AppSettings.get().get('application.mode') != 'prod'"/>
			<button name="installBtn" title="Install" colSpan="4" onClick="action-app-method-bulk-install" hidden="true"/>
		</panel>
	</form>
	
	<form model="com.axelor.apps.base.db.Wizard" title="Import access config" name="import-access-config-wizard-form">
		<panel name="wizardPanel">
			<field type="many-to-one" name="metaFile" title="File" widget="binary-link" target="com.axelor.meta.db.MetaFile"/>
			<button name="importAccessBtn" title="Import" colSpan="4" onClick="action-app-method-import-access-config" readonlyIf="metaFile == null"/>
		</panel>
	</form>
	
	<cards name="app-cards" model="com.axelor.apps.base.db.App" title="Apps" css="rect-image" orderBy="sequence" width="25%:200" > 
		<toolbar>
			<button name="bulkInstallBtn" title="Bulk install" onClick="action-app-open-bulk-install-selector"/>
			<button name="refreshAppBtn" title="Refresh Apps" onClick="action-app-method-refresh-app"/>
			<button name="importRolesBtn" title="Import roles" onClick="action-app-method-import-all-roles" />
		</toolbar>
		<field name="name" />
		<field name="code" x-bind="{{code|unaccent|uppercase}}" />
		<field name="image" />
		<field name="description"/>
		<field name="active"/>
		<field name="sequence"/>
		<template><![CDATA[
			<div>
			  <div class="span4 card-image">
			    <img ng-src="{{$image('image', 'content')}}" />
			  </div>
			  <div class="span8">
				 <strong x-translate>{{$fmt('name')}}</strong>
			  </div>
			  <div class="span12">
				<a class="btn btn-small btn-info pull-right" href="" ng-show="!active" ui-action-click="action-app-alert-install,action-app-method-install-app" x-translate>Install</a>
				<a class="btn btn-small btn-success pull-right" href="" ng-show="active" ui-action-click="com.axelor.apps.base.web.AppController:configure" x-translate>Configure</a>
				<a class="btn btn-small btn-danger pull-right" href="" ng-show="active" ui-action-click="action-app-alert-un-install,action-app-method-uninstall-app" x-translate>Uninstall</a>
			  </div>
			</div>
		]]>
		</template>
	</cards>
	
	<action-record name="action-app-bulk-install-select-all" model="com.axelor.apps.base.db.App">
	 	<field name="appsSet" expr="eval:(__repo__(App).all().filter('self.active = false or self.demoDataLoaded = false').fetch()).toSet()"/>
	</action-record>
	
	<action-method name="action-method-app-import-data-demo">
		<call class="com.axelor.apps.base.web.AppController" method="importDataDemo"/>
	</action-method>
	
	 <action-method name="action-app-method-install-app">
	    <call class="com.axelor.apps.base.web.AppController" method="installApp"  />
	 </action-method>
	 
	 <action-method name="action-app-method-uninstall-app">
	    <call class="com.axelor.apps.base.web.AppController" method="uninstallApp" />
	 </action-method>
	 
	 <action-method name="action-app-method-bulk-install" >
	 	<call class="com.axelor.apps.base.web.AppController" method="bulkInstall" />
	 </action-method>
	 
	 <action-method name="action-app-method-refresh-app">
		<call class="com.axelor.apps.base.web.AppController" method="refreshApp"/>
	 </action-method>
	 
	 <action-method name="action-app-method-import-roles">
	 	<call class="com.axelor.apps.base.web.AppController" method="importRoles"/>
	 </action-method>
	 
	 <action-method name="action-app-method-import-all-roles">
	 	<call class="com.axelor.apps.base.web.AppController" method="importAllRoles"/>
	 </action-method>
	 
	 <action-method name="action-app-method-generate-access-template">
	 	<call class="com.axelor.apps.base.web.AppController" method="generateAccessTemplate"/>
	 </action-method>
	 
	 <action-method name="action-app-method-import-access-config">
	 	<call class="com.axelor.apps.base.web.AppController" method="importAccessConfig"/>
	 </action-method>
	 
	 <action-view name="action-app-open-bulk-install-selector" title="Bulk install" model="com.axelor.apps.base.db.App">
	 	<view type="form" name="bulk-install-app-form"/>
	 	<view-param name="show-toolbar" value="false"/>
		<view-param name="popup" value="true" />  
		<view-param name="popup-save" value="false" />
		<view-param name="show-confirm" value="false" />
		<view-param name="height" value="400" />
	 </action-view>
	 
	 <action-view name="action-app-view-import-access-config-wizard" title="Import access config" model="com.axelor.apps.base.db.Wizard">
	 	<view type="form" name="import-access-config-wizard-form"/>
	 	<view-param name="show-toolbar" value="false"/>
		<view-param name="popup" value="true" />  
		<view-param name="popup-save" value="false" />
		<view-param name="show-confirm" value="false" />
	 </action-view>
	 
	 <action-attrs name="action-app-on-load-attrs">
	 	<attribute name="hidden" for="configureBtn" expr="eval:!__self__.active"/>
	 	<attribute name="hidden" for="demoDataLoaded" expr="eval:!__self__.active"/>
	 	<attribute name="hidden" for="importDataDemoBtn" expr="eval:!__self__.active || demoDataLoaded"/>
	 </action-attrs>
	 
	 <action-attrs name="action-app-bulk-install-apps-set-change">
	 	<attribute name="hidden" for="installBtn" expr="eval:appsSet == null || appsSet.empty"/>
	 </action-attrs>
	 
	 <action-validate name="action-app-alert-install">
	 	<alert message="Are you sure wants to install '${name}'?"/>
	 </action-validate>
	 
	 <action-validate name="action-app-alert-un-install">
	 	<alert message="Are you sure wants to uninstall '${name}'?"/>
	 </action-validate>
	 
	 <action-validate name="action-app-alert-demo-import">
	 	<alert message="Are you sure wants to import demo data for '${name}'?"/>
	 </action-validate>
       
</object-views>
