
<div class="modal" ng-controller="SaveAppDefinitionCtrl">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header"><h2>{{'APP.POPUP.SAVE-APP-TITLE' | translate}}</h2></div>
			<div class="modal-body">
				<p>{{'APP.POPUP.CREATE-DESCRIPTION' | translate}}</p>
				<div ng-if="saveDialog.errorMessage && saveDialog.errorMessage.length > 0" class="alert error" style="font-size: 14px; margin-top:20px">
                  <div class="popup-error" style="font-size: 14px">
                    <span class="glyphicon glyphicon-remove-circle"></span>
                    <span>{{saveDialog.errorMessage}}</span>
                  </div>
                </div>
				<div class="form-group">
				    <label for="appName">{{'APP.NAME' | translate}}</label>
				    <input ng-disabled="model.loading" type="text" class="form-control"
			               id="appName" ng-model="saveDialog.name" ui-keypress="{13:'ok()'}" auto-focus>
				</div>
				<div class="form-group">
				    <label for="appKey">{{'APP.KEY' | translate}}</label>
				    <input ng-disabled="model.loading" type="text" class="form-control"
			               id="appKey" ng-model="saveDialog.key">
				</div>
				<div class="form-group">
				    <label for="appDescription">{{'APP.DESCRIPTION' | translate}}</label>
					<textarea ng-disabled="model.loading" class="form-control" id="appDescription" rows="5" ng-model="saveDialog.description"></textarea>
				</div>
                <div class="checkbox" ng-if="currentAppDefinition.definition &&
				    ((currentAppDefinition.definition.models && currentAppDefinition.definition.models.length > 0)
				            || (currentAppDefinition.definition.cmmnModels && currentAppDefinition.definition.cmmnModels.length > 0)) ">

                <label>
                        <input type="checkbox" ng-model="saveDialog.publish">
                            {{'APP.POPUP.PUBLISH-FIELD' | translate}}
                    </label>
                </div>
                
                <div ng-if="error && (error.hasCustomStencilItem || error.hasValidationErrors) && !status.loading" class="alert error" style="font-size: 14px; margin-top:20px">
                    <div class="popup-error" style="font-size: 14px">
                        <span class="glyphicon glyphicon-remove-circle"></span>
                        <span ng-if="error.hasCustomStencilItem">{{'APP.POPUP.HAS-CUSTOM-STENCILITEM' | translate:error}}</span>
                        <span ng-if="error.hasValidationErrors">{{'APP.POPUP.HAS-VALIDATIONERROR' | translate:error}}</span>
                    </div>
                </div>

                <div ng-if="conflict && conflict.type && conflict.type == 'conflictingProcDefKey'"
                     class="alert-danger app-publish-error" role="alert">
                    <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true" style="margin-right: 2px"></span>
                    <span>{{'APP.POPUP.PUBLISH-ERROR-PROCDEF-KEY-CONFLICT' | translate:conflict.data}}</span>
                </div>

                <div ng-if="conflict && conflict.type && conflict.type == 'duplicateProcDefKeys'"
                     class="alert-danger app-publish-error" role="alert">
                    <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true" style="margin-right: 2px"></span>
                    <span>{{'APP.POPUP.PUBLISH-ERROR-PROCDEF-DUPLICATE-KEYS' | translate}}</span>
                    <ul>
                        <li ng-repeat="entry in conflict.data.duplicateProcessDefinitionIds">
                            <span ng-repeat="(id, name) in entry">{{id}} ({{name}})</span>
                        </li>
                    </ul>
                </div>

                <div ng-if="conflict && conflict.type && conflict.type == 'processModelAlreadyUsed'"
                     class="alert-warning app-publish-error" role="alert">
                    <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true" style="margin-right: 2px"></span>
                    <span>{{'APP.POPUP.PUBLISH-ERROR-PROCESS-ALREADY-USED' | translate}}</span>
                    <ul>
                        <li ng-repeat="processName in conflict.data.conflictingProcessModelNames track by $index">
                            {{processName}} ({{'APP.POPUP.PUBLISH-ERROR-PROCESS-ALREADY-USED-APP' | translate}} "{{conflict.data.conflictingAppNames[$index]}}")
                        </li>
                    </ul>
                </div>

			</div>
			
			<div class="modal-footer">

				<div class="pull-right" ng-if="conflict == null || conflict == undefined || conflict.type != 'processModelAlreadyUsed'">
					<button class="btn btn-sm btn-default" ng-click="cancel()" ng-disabled="model.loading" translate>GENERAL.ACTION.CANCEL</button>
					<button class="btn btn-primary" ng-click="saveAndClose()" ng-disabled="status.loading || saveDialog.name.length == 0 || saveDialog.key.length == 0" ng-show="!error && !error.hasCustomStencilItem && !error.hasValidationErrors" translate>ACTION.SAVE-AND-CLOSE</button>
					<button class="btn btn-primary" ng-click="save()" ng-disabled="status.loading || saveDialog.name.length == 0 || saveDialog.key.length == 0" ng-show="!error && !error.hasCustomStencilItem && !error.hasValidationErrors" translate>ACTION.SAVE</button>
				</div>

                <div class="pull-right" ng-if="conflict && conflict.type == 'processModelAlreadyUsed'">
                    <button type="button" class="btn btn-sm btn-default" ng-click="cancel()" ng-disabled="popup.loading">
                        {{'GENERAL.ACTION.CANCEL' | translate}}
                    </button>
                    <button type="button" class="btn btn-sm btn-success" style="background-color: #5cb85c;border-color: #4cae4c;" ng-click="saveAndClose(true)" ng-disabled="popup.loading">
                        <span>{{'GENERAL.ACTION.CONFIRM-AND-CLOSE' | translate}}</span>
                    </button>
                    <button type="button" class="btn btn-sm btn-success" style="background-color: #5cb85c;border-color: #4cae4c;" ng-click="save(true)" ng-disabled="popup.loading">
                        <span>{{'GENERAL.ACTION.CONFIRM' | translate}}</span>
                    </button>
                </div>

				<div class="loading pull-right" ng-show="model.loading">
					<div class="l1"></div><div class="l2"></div><div class="l2"></div>
				</div>
			</div>
		</div>
	</div>
</div>