- fix for tinymce usage where rather than collect all changes before unload, capture the onblur event and set the value then.

- use fle type image rather than rendering template icon in create web content summary screen
- save content before executing finish or next in create web content wizard - makes error handling more proper
- add output path pattern to summary screen for create form wizard
- handle chiba-state-changed event properly 

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4514 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ariel Backenroth
2006-12-05 02:24:08 +00:00
parent e57a636bc3
commit d8e78b8e22
6 changed files with 1079 additions and 1004 deletions

View File

@@ -56,6 +56,7 @@ import org.alfresco.web.forms.FormProcessor;
import org.alfresco.web.forms.FormsService;
import org.alfresco.web.forms.Rendition;
import org.alfresco.web.forms.RenditionImpl;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.wcm.component.UIUserSandboxes;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -66,7 +67,7 @@ import org.w3c.dom.Document;
*/
public class CreateWebContentWizard extends BaseContentWizard
{
private static final Log logger = LogFactory.getLog(CreateWebContentWizard.class);
private static final Log LOGGER = LogFactory.getLog(CreateWebContentWizard.class);
protected String content = null;
protected String formName;
@@ -154,6 +155,56 @@ public class CreateWebContentWizard extends BaseContentWizard
}
}
@Override
public String next()
{
final int step = Application.getWizardManager().getCurrentStep();
if (step == 3)
{
try
{
this.saveContent();
}
catch (Exception e)
{
Application.getWizardManager().getState().setCurrentStep(step - 1);
Utils.addErrorMessage(e.getMessage(), e);
}
}
return super.next();
}
@Override
public String back()
{
final int step = Application.getWizardManager().getCurrentStep();
if (step == 2)
{
LOGGER.debug("clearing form instance data");
this.formInstanceData = null;
this.renditions = null;
}
return super.back();
}
@Override
public String finish()
{
if (this.formInstanceData == null || this.renditions == null)
{
try
{
this.saveContent();
}
catch (Exception e)
{
Utils.addErrorMessage(e.getMessage(), e);
return super.getErrorOutcome(e);
}
}
return super.finish();
}
@Override
protected String finishImpl(final FacesContext context, final String outcome)
throws Exception
@@ -278,13 +329,9 @@ public class CreateWebContentWizard extends BaseContentWizard
boolean disabled = false;
int step = Application.getWizardManager().getCurrentStep();
switch(step)
{
case 1:
if (step == 1)
{
disabled = (this.fileName == null || this.fileName.length() == 0);
break;
}
}
return disabled;
@@ -292,25 +339,20 @@ public class CreateWebContentWizard extends BaseContentWizard
/**
* Save the specified content using the currently set wizard attributes
*
* @param fileContent File content to save
* @param strContent String content to save
*/
@Override
protected void saveContent(File fileContent, String strContent) throws Exception
protected void saveContent()
throws Exception
{
final FormsService fs = FormsService.getInstance();
if (logger.isDebugEnabled())
logger.debug("saving file content to " + this.fileName);
if (LOGGER.isDebugEnabled())
LOGGER.debug("saving file content to " + this.fileName);
// get the parent path of the location to save the content
String path = this.avmBrowseBean.getCurrentPath();
path = path.replaceFirst(AVMConstants.STORE_MAIN, AVMConstants.STORE_PREVIEW);
if (MimetypeMap.MIMETYPE_XML.equals(this.mimeType) && this.formName != null)
{
final Document formInstanceData = (fileContent != null
? fs.parseXML(fileContent)
: fs.parseXML(strContent));
final Document formInstanceData = fs.parseXML(this.content);
path = this.getForm().getOutputPathForFormInstanceData(path, this.fileName, formInstanceData);
final String[] sb = AVMNodeConverter.SplitBase(path);
@@ -319,28 +361,23 @@ public class CreateWebContentWizard extends BaseContentWizard
}
if (logger.isDebugEnabled())
logger.debug("reseting layer " + path.split(":")[0] + ":/" + AVMConstants.DIR_APPBASE);
if (LOGGER.isDebugEnabled())
LOGGER.debug("reseting layer " + path.split(":")[0] + ":/" + AVMConstants.DIR_APPBASE);
this.avmSyncService.resetLayer(path.split(":")[0] + ":/" + AVMConstants.DIR_APPBASE);
if (logger.isDebugEnabled())
logger.debug("creating all directories in path " + path);
if (LOGGER.isDebugEnabled())
LOGGER.debug("creating all directories in path " + path);
fs.makeAllDirectories(path);
if (logger.isDebugEnabled())
logger.debug("creating file " + this.fileName + " in " + path);
if (LOGGER.isDebugEnabled())
LOGGER.debug("creating file " + this.fileName + " in " + path);
// put the content of the file into the AVM store
if (fileContent != null)
{
avmService.createFile(path, this.fileName, new BufferedInputStream(new FileInputStream(fileContent)));
}
else
{
avmService.createFile(path, this.fileName, new ByteArrayInputStream((strContent == null ? "" : strContent).getBytes()));
}
avmService.createFile(path,
this.fileName,
new ByteArrayInputStream((this.content == null ? "" : this.content).getBytes()));
// remember the created path
this.createdPath = path + '/' + this.fileName;
@@ -424,10 +461,18 @@ public class CreateWebContentWizard extends BaseContentWizard
// add the configured create mime types to the list
ConfigService svc = Application.getConfigService(context);
Config wizardCfg = svc.getConfig("Content Wizards");
if (wizardCfg != null)
if (wizardCfg == null)
{
LOGGER.warn("Could not find 'Content Wizards' configuration section");
}
else
{
ConfigElement typesCfg = wizardCfg.getConfigElement("create-mime-types");
if (typesCfg != null)
if (typesCfg == null)
{
LOGGER.warn("Could not find 'create-mime-types' configuration element");
}
else
{
for (ConfigElement child : typesCfg.getChildren())
{
@@ -443,17 +488,8 @@ public class CreateWebContentWizard extends BaseContentWizard
QuickSort sorter = new QuickSort(this.objectTypes, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
}
else
{
logger.warn("Could not find 'create-mime-types' configuration element");
}
}
else
{
logger.warn("Could not find 'Content Wizards' configuration section");
}
}
return this.createMimeTypes;
}
@@ -509,12 +545,7 @@ public class CreateWebContentWizard extends BaseContentWizard
}
public FormInstanceData getFormInstanceData()
throws Exception
{
if (this.formInstanceData == null)
{
this.saveContent(null, this.content);
}
return this.formInstanceData;
}
@@ -543,24 +574,6 @@ public class CreateWebContentWizard extends BaseContentWizard
return this.startWorkflow;
}
/**
* @return Returns the summary data for the wizard.
*/
public String getSummary()
{
ResourceBundle bundle = Application.getBundle(FacesContext.getCurrentInstance());
// TODO: show first few lines of content here?
return buildSummary(
new String[] {bundle.getString("file_name"),
bundle.getString("content_type"),
bundle.getString("Location")},
new String[] {this.fileName, getSummaryObjectType(),
getSummaryMimeType(this.mimeType)});
}
// ------------------------------------------------------------------------------
// Action event handlers

View File

@@ -44,4 +44,7 @@ public interface Rendition
/** the url to the asset */
public String getUrl();
/** the file type image for the rendition */
public String getFileTypeImage();
}

View File

@@ -34,6 +34,7 @@ import org.alfresco.service.cmr.repository.TemplateService;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.wcm.AVMConstants;
import org.alfresco.web.ui.common.Utils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -105,6 +106,11 @@ public class RenditionImpl
return AVMConstants.buildAVMAssetUrl(AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond());
}
public String getFileTypeImage()
{
return Utils.getFileTypeImage(this.getName(), false);
}
private ServiceRegistry getServiceRegistry()
{
final FacesContext fc = FacesContext.getCurrentInstance();

View File

@@ -42,6 +42,7 @@
<jsp:attribute name="description">
<div>${WizardManager.bean.formDescription}</div>
<div>${msg.schema_root_element_name}: ${WizardManager.bean.schemaRootElementName}</div>
<div>${msg.schema_root_element_name}: ${WizardManager.bean.outputPathPatternForFormInstanceData}</div>
</jsp:attribute>
</a:listItem>
</a:selectList>

View File

@@ -53,7 +53,7 @@
<c:forEach items="${WizardManager.bean.renditions}" var="rendition">
<a:listItem label="${rendition.name}"
value="${rendition.name}"
image="/images/icons/template_large.gif">
image="${rendition.fileTypeImage}">
<jsp:attribute name="description">
<span style="float:right">
<a:actionLink value="${rendition.name}"

View File

@@ -32,7 +32,6 @@ tinyMCE.init({
auto_resize: false,
force_p_newlines: false,
encoding: null,
save_callback: "document.xform.setXFormsValue",
add_unload_trigger: false,
add_form_submit_trigger: false,
theme_advanced_toolbar_location: "top",
@@ -82,11 +81,6 @@ dojo.declare("alfresco.xforms.Widget",
this._updateDisplay();
this.hideAlert();
},
setRequired: function(b)
{
this.required = b;
this._updateDisplay();
},
isValidForSubmit: function()
{
if (!this.valid)
@@ -108,13 +102,29 @@ dojo.declare("alfresco.xforms.Widget",
}
return result;
},
setEnabled: function(enabled)
{
},
setRequired: function(b)
{
this.required = b;
this._updateDisplay();
},
isRequired: function()
{
if (typeof this.required != "undefined")
return this.required;
var binding = this.xform.getBinding(this.xformsNode);
return binding && binding.required == "true()";
},
setReadonly: function(readonly)
{
this.readonly = readonly;
},
isReadonly: function()
{
if (typeof this.readonly != "undefined")
return this.readonly;
var binding = this.xform.getBinding(this.xformsNode);
return binding && binding.readonly == "true()";
},
@@ -252,6 +262,10 @@ dojo.declare("alfresco.xforms.DatePicker",
this,
this._datePicker_setDateHandler);
},
setValue: function(value)
{
throw new Error("setValue unimplemented for DatePicker");
},
getValue: function()
{
return (this.widget.value == null || this.widget.value.length == 0
@@ -314,6 +328,10 @@ dojo.declare("alfresco.xforms.TextField",
dojo.event.connect(this.widget, "onblur", this, this._widget_changeHandler);
}
},
setValue: function(value)
{
this.widget.setAttribute("value", value);
},
getValue: function()
{
var result = this.widget.value;
@@ -342,12 +360,27 @@ dojo.declare("alfresco.xforms.TextArea",
this.domNode.style.height = "200px";
this.domNode.innerHTML = this.getInitialValue() || "";
tinyMCE.addMCEControl(this.domNode, this.id);
tinyMCE.getInstanceById(this.id).iframeElement.onblur = function() { alert('foo'); };
//dojo.event.connect(tinyMCE.getInstanceById(this.id).iframeElement,
var editorDocument = tinyMCE.getInstanceById(this.id).getDoc();
editorDocument.widget = this;
tinyMCE.addEvent(editorDocument, "blur", this._tinyMCE_blurHandler);
this.widget = this.domNode;
},
setValue: function(value)
{
tinyMCE.getInstanceById(this.id).setContent(value);
},
getValue: function()
{
return tinyMCE.getContent(this.id);
},
_tinyMCE_blurHandler: function(event)
{
var widget = event.target.widget;
widget.xform.setXFormsValue(widget.id, widget.getValue());
},
_destroy: function()
{
this.inherited("_destroy", []);
@@ -453,6 +486,10 @@ dojo.declare("alfresco.xforms.Select",
dojo.event.connect(this.widget, "onblur", this, this._list_changeHandler);
}
},
setValue: function(value)
{
throw new Error("setValue unimplemented for Select");
},
getValue: function()
{
return this._selectedValues.join(" ");
@@ -543,6 +580,10 @@ dojo.declare("alfresco.xforms.Select1",
dojo.event.connect(this.widget, "onchange", this, this._combobox_changeHandler);
}
},
setValue: function(value)
{
throw new Error("setValue unimplemented for Select1");
},
getValue: function()
{
return this._selectedValue;
@@ -587,6 +628,10 @@ dojo.declare("alfresco.xforms.Checkbox",
this.widget.setAttribute("checked", true);
dojo.event.connect(this.widget, "onclick", this, this._checkbox_clickHandler);
},
setValue: function(value)
{
this.widget.checked = value == "true";
},
getValue: function()
{
return this.widget.checked;
@@ -1048,11 +1093,13 @@ dojo.declare("alfresco.xforms.Repeat",
this.domNode = this.inherited("render", [ attach_point ]);
this.domNode.style.border = "1px solid black";
var marginLeft = this.getParentRepeats().length * 10;
this.domNode.style.marginLeft = marginLeft + "px";
var parentRepeats = this.getParentRepeats();
this.domNode.style.marginLeft = (parentRepeats.length * 10) + "px";
this.domNode.style.marginRight = (parseInt(this.domNode.style.marginLeft) / 2) + "px";
this.domNode.style.width = (this.domNode.offsetParent.offsetWidth -
parseInt(this.domNode.style.borderWidth) -
marginLeft) + "px";
parseInt(this.domNode.style.marginLeft) -
parseInt(this.domNode.style.marginRight)) + "px";
this.groupHeaderNode.repeat = this;
this.groupHeaderNode.style.position = "relative";
@@ -1145,7 +1192,7 @@ dojo.declare("alfresco.xforms.Repeat",
},
_toggleExpanded_clickHandler: function(event)
{
this.setExpanded(!this.isExpanded())
this.setExpanded(!this.isExpanded());
},
_updateRepeatControls: function()
{
@@ -1239,7 +1286,6 @@ dojo.declare("alfresco.xforms.Submit",
{
dojo.debug("triggering submit from handler " + event.target.id);
dojo.event.browser.stopEvent(event);
tinyMCE.triggerSave(true, false);
_hide_errors();
xform.submitWidget.currentButton = event.target;
xform.submitWidget.widget.buttonClick();
@@ -1551,9 +1597,15 @@ dojo.declare("alfresco.xforms.XForm",
}
case "chiba-state-changed":
{
var valid = xfe.properties["valid"] == "true";
xfe.getTarget().setValid(valid);
xfe.getTarget().setModified(true);
xfe.getTarget().setValid(xfe.properties["valid"] == "true");
xfe.getTarget().setRequired(xfe.properties["required"] == "true");
xfe.getTarget().setReadonly(xfe.properties["readonly"] == "true");
xfe.getTarget().setEnabled(xfe.properties["enabled"] == "true");
if ("value" in xfe.properties)
{
xfe.getTarget().setValue(xfe.properties["value"]);
}
break;
}
case "chiba-prototype-cloned":