explorer.js
来自「Hippo CMS是一个以信息为中心的开源内容管理系统。Hippo CMS目标是」· JavaScript 代码 · 共 809 行 · 第 1/2 页
JS
809 行
/*
* Copyright 2001-2008 Hippo (www.onehippo.com)
*
* Licensed 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.
*/
/*
* explorer.js
*
* User Interface layer for the CMS Editor Framework
*
*/
cocoon.load("site:/avalon/avalon.js");
cocoon.load("site:/workflow/workflow.js");
cocoon.load("site:/util/flow/lib-io.js");
cocoon.load("site:/spring/spring.js");
importClass(Packages.java.io.BufferedOutputStream);
importClass(Packages.java.io.File);
importClass(Packages.java.io.FileOutputStream);
importClass(Packages.java.util.HashSet);
importClass(Packages.java.util.HashMap);
importClass(Packages.nl.hippo.uidgenerator.UIDGenerator);
importClass(Packages.nl.hippo.util.FileDeletionTask);
importClass(Packages.nl.hippo.cms.contentmodel.WebdavRepository);
importClass(Packages.org.apache.cocoon.components.cron.JobScheduler);
importClass(Packages.org.apache.excalibur.store.Store);
importClass(Packages.org.apache.cocoon.caching.EventAwareManager);
// cocoon forms
//cocoon.load("resource://org/apache/cocoon/forms/flow/javascript/Form.js");
cocoon.load("resource://nl/hippo/cocoon/forms/flow/javascript/Form.js");
importClass(Packages.org.apache.cocoon.components.modules.input.InputModule);
// globals
var perspective = null;
// - Sitemap functions ------------------------------------------------
/**
* Manages a HashSet representing the folder tree as viewed by the client.
* The HashSet is stored as a session attribute ("tree + perspective").
*
* @param path specifies the node on which an action must be performed (expand or collapse).
*/
function tree() {
var path = cocoon.parameters["path"];
var perspective = cocoon.parameters["perspective"];
// each entry in "tree" is a path to a currently expanded node in the folder tree
if(perspective == null || perspective == '')
{
if (path.length > 2 && path.charAt(path.length-1) == '/') {
perspective = path.substring(0, path.length - 1);
}
}
var tree = cocoon.session.getAttribute("tree" + perspective);
// get the requested action (expand or collapse)
var action = cocoon.request.get("action");
/*
print("tree: action is: "+action);
var names = cocoon.request.getParameterNames();
while(names.hasMoreElements())
{
var name = names.nextElement();
var value = cocoon.request.get(name);
print(name+" => "+value);
}
*/
// remove trailing slash
if (path.length > 2 && path.charAt(path.length-1) == '/') {
path = path.substring(0, path.length - 1);
}
if (tree == null) { // initialize tree
tree = new HashSet();
cocoon.session.setAttribute("tree"+perspective, tree);
if(action != "expandPath")
{
tree.add(path);
}
}
if (tree.contains(path)) { // collapse or browser refresh
if (action == "collapse") {
tree.remove(path);
}
if (action != "collapse")
{
var folders = path.split("/");
var newPath = "";
for(var i=1;i<folders.length;i++){
newPath += "/" + folders[i];
if(!tree.contains(newPath))
{
tree.add(newPath);
}
}
}
}
else /*if (action == "expandPath") */
{
var folders = path.split("/");
var newPath = "";
for(var i=1;i<folders.length;i++){
newPath += "/" + folders[i];
if(!tree.contains(newPath))
{
tree.add(newPath);
}
}
}
/*else // expand is default action
tree.add(path);*/
var refresh = cocoon.request.get("refresh");
if(refresh == null)
refresh = "";
cocoon.session.setAttribute("tree" + perspective, tree);
cocoon.sendPage("tree" , {refresh: refresh, perspective: perspective });
//cocoon.sendPage("tree.jx", {"tree" : tree});
}
/**
* Shows a Cocoon Form for the possible actions on the resource specified by resourceId,
* and, on a submit of the form, calls the corresponding (workflow-) action.
*/
function actionsform2xml(form) {
var resourceId = cocoon.parameters["resourceId"];
var uriPrefix = cocoon.parameters["uriPrefix"];
var uri = uriPrefix + resourceId;
var repositoryFiles = cocoon.parameters["repositoryFiles"];
var resourceType;
if (form.lookupWidget('resourceType') != null &&
form.lookupWidget('resourceType').getValue() != '')
resourceType = form.lookupWidget('resourceType').getValue();
else
resourceType = resourceId;
if (cocoon.log.isDebugEnabled()) {
cocoon.log.debug("explorer.js: resourceId: " + resourceId);
cocoon.log.debug("explorer.js: resourceType: " + resourceType);
}
form.setFormName("site.explorer.flow.explorer.actionsform."+resourceType+"@"+cocoon.session);
form.setUseUniqueContinuations(true);
form.showForm("actionsform-display-pipeline" + resourceId);
var actionId = form.submitId;
var actionIdShort = actionId.substring(actionId.indexOf(':')+1, actionId.length());
if (cocoon.log.isDebugEnabled()) {
cocoon.log.debug("explorer.js: actionId: " + actionId);
cocoon.log.debug("explorer.js: actionIdShort: " + actionIdShort );
}
var widgets = form.form.getChildren();
var params = new HashMap();
var typeWidget;
var nameWidget;
if(form.form.lookupWidget("documents_newDocument-type")!=null)
{
typeWidget = form.form.lookupWidget("documents_newDocument-type");
}
if(form.form.lookupWidget("documents_newDocument-name")!=null)
{
nameWidget = form.form.lookupWidget("documents_newDocument-name");
}
while (widgets.hasNext())
{
var tmp = widgets.next();
var id = tmp.getId();
if (id.startsWith(actionIdShort + "-"))
{
params.put(id.substring(id.indexOf('-') + 1), tmp.getValue());
}
else if (id.indexOf(':') >= 0 && id.substring(id.indexOf(':') + 1).startsWith(actionIdShort + "-"))
{
params.put(id.substring(id.indexOf('-') + 1), tmp.getValue());
}
}
if (cocoon.log.isDebugEnabled())
{
cocoon.log.debug("explorer.js: actionsform2xml: params: keys: " + params.keySet());
cocoon.log.debug("explorer.js: actionsform2xml: params: values: "+ params.values());
}
var actionEvent;
var actionSuccess;
if (params.get("standardUIAction") == "hippo.cms.save") { // special case for edit/save
actionEvent = "editDocument";
if (editDocument(uriPrefix, resourceId, params)) {
actionSuccess = "success";
}
else {
actionSuccess = "failure";
}
}
else if (form.submitId.indexOf('_') == -1) { // workflow action
lastResponseStatus = "0";
var workflowActionId = params.get("actionId");
if (workflowActionId != null) {
if (cocoon.log.isDebugEnabled()) {
cocoon.log.debug("explorer.js: workflow action: " + form.submitId + " = " + workflowActionId);
cocoon.log.debug("explorer.js: standard ui action: " + params.get("standardUIAction"));
}
var standardUIAction = params.get("standardUIAction");
var cmsAction = null;
if (standardUIAction != null) {
if (standardUIAction.equals("hippo.cms.delete")) {
cmsAction = "deleteResource";
}
else if (standardUIAction.equals("hippo.cms.archive")) {
cmsAction = "deleteResource";
}
else if (standardUIAction.equals("hippo.cms.movedocument")) {
cmsAction = "moveDocument";
}
}
if (workflow.invokeAction(resourceId, workflowActionId, params, uriPrefix)) {
if (cmsAction != null) {
if (this[cmsAction].call(this, uriPrefix, resourceId, params)) {
if (cocoon.log.isDebugEnabled()) {
cocoon.log.debug("explorer.js: standardUIAction completed");
}
if(cmsAction.equals("moveDocument")){
// fire invalidation events
var emanager = cocoon.getComponent(EventAwareManager.ROLE);
WebdavRepository.fireEvent(emanager,uriPrefix+resourceId);
WebdavRepository.fireEvent(emanager,params.get("repositoryRootUrl")+params.get("moveDocumentTargetLocation"));
}
}
else {
if (cocoon.log.isDebugEnabled()) {
cocoon.log.debug("explorer.js: standardUIAction failed");
}
actionEvent = actionId;
actionSuccess = "failure";
}
}
else {
cmsAction = "workflowAction";
// after workflowAction fire invalidation events
var emanager = cocoon.getComponent(EventAwareManager.ROLE);
WebdavRepository.fireEvent(emanager,uriPrefix+resourceId);
}
actionEvent = cmsAction;
actionSuccess = "success";
}
else {
lastResponseStatus = "401";
actionEvent = actionId;
actionSuccess = "failure";
}
}
else {
lastResponseStatus = "400";
actionEvent = actionId;
actionSuccess = "failure";
}
if(resourceType.equals("assetsFile")) {
actionEvent = "asset" + actionEvent;
}
}
else { // other action
// read the requested action from form.submitId (string-part after '_')
var action = form.submitId.substring(form.submitId.indexOf("_") + 1);
if (cocoon.log.isDebugEnabled()) {
cocoon.log.debug("explorer.js: action: " + action);
}
if (resourceId.indexOf('/imageresources/') == 0)
{
actionEvent = "imageresources" + action;
}
else if (form.submitId.substring(0, form.submitId.indexOf("_")).equals("assets")) {
actionEvent = "asset" + action;
}
else if (resourceId.indexOf('/static/') == 0)
{
actionEvent = "static" + action;
}
else if (resourceId.indexOf('/imageset/') == 0)
{
actionEvent = "imageset" + action;
}
else if (resourceId.indexOf('/imageresources/') == 0)
{
actionEvent = "imageresources" + action;
}
else if (resourceId.indexOf('/importdms/') == 0)
{
actionEvent = "dms" + action;
}
else {
actionEvent = action;
}
// do the requested action
if (this[action].call(this, uriPrefix, resourceId, params)) {
actionSuccess = "success";
var emanager = cocoon.getComponent(EventAwareManager.ROLE);
WebdavRepository.fireEvent(emanager,uriPrefix+resourceId);
}
else {
actionSuccess = "failure";
}
}//end other action
// check for a name parameter and pass it as a request parameter
var name = "";
if (params.get("name") != null) {
name = spring.getBean("nameUtil").convertToValidName(params.get("name"));
}
else if (params.get("File") != null) {
var tempName = new File(params.get("File")).getName();
name = spring.getBean("nameUtil").convertToValidBinaryFilename(tempName);
}
//print("action" + actionSuccess + "?resourceId=" + resourceId + "&name=" + name + ",action:" + actionEvent + "," +lastResponseStatus);
cocoon.sendPage("action" + actionSuccess + "?resourceId=" + resourceId + "&name=" + name,
{status: lastResponseStatus, actionEvent: actionEvent});
}
/**
* Shows a Cocoon Form for the possible actions on the resource specified by resourceId,
* and, on a submit of the form, calls the corresponding (workflow-) action.
*/
function toolbarform2xml(form) {
var resourceId = cocoon.parameters["resourceId"];
var uriPrefix = cocoon.parameters["uriPrefix"];
var uri = uriPrefix + resourceId;
var repositoryFiles = cocoon.parameters["repositoryFiles"];
form.setFormName("site.explorer.flow.explorer.toolbarform2xml"+cocoon.session);
form.setUseUniqueContinuations(true);
form.showForm("toolbarform-display-pipeline" + resourceId);
var actionId = form.submitId;
var actionIdShort = actionId.substring(actionId.indexOf('_')+1, actionId.length());
if (cocoon.log.isDebugEnabled()) {
cocoon.log.debug("explorer.js: actionId: " + actionId);
cocoon.log.debug("explorer.js: actionIdShort: " + actionIdShort );
}
var widgets = form.form.getChildren();
var params = new HashMap();
while (widgets.hasNext())
{
var tmp = widgets.next();
var id = tmp.getId();
if (id.startsWith(actionIdShort + "-"))
{
params.put(id.substring(id.indexOf('-') + 1), tmp.getValue());
}
else if (id.indexOf('_') >= 0 && id.substring(id.indexOf('_') + 1).startsWith(actionIdShort + "-"))
{
params.put(id.substring(id.indexOf('-') + 1), tmp.getValue());
}
}
if (cocoon.log.isDebugEnabled())
{
cocoon.log.debug("explorer.js: actionsform2xml: params: keys: " + params.keySet());
cocoon.log.debug("explorer.js: actionsform2xml: params: values: "+ params.values());
}
var actionEvent;
var actionSuccess;
if (params.get("standardUIAction") == "hippo.cms.save") { // special case for edit/save
actionEvent = "editDocument";
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?