blob: 755ea7f1c660a6b8e7301647f642822606a56dc7 [file] [log] [blame]
<%
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
include('/controllers/login/validator.jag');
include('/controllers/menu/menu_generator.jag');
var log = new Log("apachestratos.applications_form"),
error = [],
listData,
caramel = require('caramel'),
context = caramel.configs().context,
menuJson = require('/controllers/menu/menu.json'),
util = require('/controllers/rest/rest_calls.jag'),
uriMatcher = new URIMatcher(request.getRequestURI()),
elements = uriMatcher.match('/{context}/{formtype}/'),
breadcrumbPathLevelOne = 'applications',
formDataEdit = topologyData = editorGroups = editorCartridges = editorAutoscalePolicies = applicationHbs = '',
editorDeploymentPolicies = applicationPolicyData = applicationJSON = '',
isEdit = isForm = false,
userPermissions = session.get('PERMISSIONS'),
dasStatsPublisherEnabled = application.get("dasStatsPublisherEnabled"),
meteringDashboardUrl = '';
//create left menu
var leftMenu = menuGenerator(context, menuJson.menu, userPermissions);
if (!elements) {
elements = uriMatcher.match('/{context}/{formtype}/{action}/');
if (!elements) {
elements = uriMatcher.match('/{context}/{formtype}/{applicationId}/{action}');
var applicationName = elements.applicationId;
//get application json
applicationJSON = util.RESTCalls.getApplicationJSON(applicationName);
var applicationAlias = applicationJSON.alias;
if (elements.action == 'view') {
applicationHbs = 'applicationView';
} else if (elements.action == 'deploy') {
applicationHbs = 'applicationDeploy';
applicationPolicyData = util.RESTCalls.getApplicationPolicies();
} else if (elements.action == 'signup') {
applicationHbs = 'applicationSignup';
}
} else {
try {
var formData = require('controllers/forms/schema/applications/' + elements.formtype + '.json'),
formDataRaw = require('controllers/forms/default/applications/' + elements.formtype + '.json'),
formTitle = formData.title,
buttonText = formData.name;
} catch (e) {
log.error(e.message);
error.push({"errorMessage": e.message});
}
isForm = true;
if (elements.formtype == 'applications' && elements.action != 'new') {
applicationHbs = 'applicationTopology';
topologyData = util.RESTCalls.getApplicationTopology(elements.action);
//get application json
applicationJSON = util.RESTCalls.getApplicationJSON(elements.action);
} else if (elements.formtype == 'applications' && elements.action == 'new') {
applicationHbs = 'applicationEditor';
editorGroups = util.RESTCalls.getGroups();
editorCartridges = util.RESTCalls.getCartridges();
editorAutoscalePolicies = util.RESTCalls.getPolicyAutoScales();
editorDeploymentPolicies = util.RESTCalls.getPolicyDeployments();
}
}
}
var formtype = elements.formtype;
switch (formtype) {
case "applications":
formTitle = "Application",
buttonText = "Application";
listData = util.RESTCalls.getApplications();
if (listData.status == 'error') {
listData = null;
}
break;
default:
error.push({"errorMessage": "Incorrect resource path found"});
}
if (dasStatsPublisherEnabled) {
meteringDashboardUrl = application.get("meteringDashboardUrl");
}
var caramelData = {
breadcrumbPathLevelOne: breadcrumbPathLevelOne,
breadcrumbPathLevelTwo: '',
left_menu: leftMenu,
isForm: isForm,
isEdit: isEdit,
appName: elements.action,
topologyData: JSON.stringify(topologyData),
editorGroups: JSON.stringify(editorGroups),
editorCartridges: JSON.stringify(editorCartridges),
editorAutoscalePolicies: JSON.stringify(editorAutoscalePolicies),
editorDeploymentPolicies: JSON.stringify(editorDeploymentPolicies),
applicationHbs: applicationHbs,
applicationPolicyData: applicationPolicyData,
applicationAlias: applicationAlias,
applicationName: applicationName,
applicationJSON: JSON.stringify(applicationJSON),
applicationStatus: applicationJSON.status,
formTitle: formTitle,
formDataRaw: JSON.stringify(formDataRaw),
formtype: elements.formtype,
buttonText: buttonText,
//formDataRaw: JSON.stringify(partition_data.partition[0]),
formDataEdit: JSON.stringify(formDataEdit),
formData: JSON.stringify(formData),
listData: listData,
error: error,
dasStatsPublisherEnabled: dasStatsPublisherEnabled,
meteringDashboardUrl: meteringDashboardUrl
}
caramel.render(caramelData);
%>