Skip to content

Commit

Permalink
PRESIDECMS-2559 Update import fields UX. Remove actions import.
Browse files Browse the repository at this point in the history
  • Loading branch information
teonator committed Sep 21, 2023
1 parent bf9063e commit 9a26064
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<form i18nBaseUri="formbuilder:importForm.">
<form i18nBaseUri="formbuilder:importFormFields.">
<tab id="default">
<fieldset id="default" sortorder="10">
<field name="file" sortorder="10" required="true" control="fileupload" preprocessor="fileUpload" accept="application/xml,text/xml" />
Expand Down
24 changes: 12 additions & 12 deletions system/handlers/admin/FormBuilder.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -848,8 +848,8 @@ component extends="preside.system.base.AdminHandler" {
}
}

public void function importForm( event, rc, prc, args ) {
prc.pageTitle = translateResource( "formbuilder:importForm.page.title" );
public void function importFormFields( event, rc, prc, args ) {
prc.pageTitle = translateResource( "formbuilder:importFormFields.page.title" );
prc.pageIcon = "file-import";

event.addAdminBreadCrumb(
Expand All @@ -858,7 +858,7 @@ component extends="preside.system.base.AdminHandler" {
);
}

public string function importFormAction( event, rc, prc, args ) {
public string function importFormFieldsAction( event, rc, prc, args ) {
var formId = rc.id ?: "";

var formData = event.getCollectionWithoutSystemVars()
Expand All @@ -869,14 +869,14 @@ component extends="preside.system.base.AdminHandler" {

formData.validationResult = validationResult;

setNextEvent( url=event.buildAdminLink( linkTo="formbuilder.importForm", queryString="id=#formId#" ), persistStruct=formData );
setNextEvent( url=event.buildAdminLink( linkTo="formbuilder.importFormFields", queryString="id=#formId#" ), persistStruct=formData );
}

try {
var xml = XmlParse( formData.file.binary );

var taskId = createTask(
event = "admin.FormBuilder.importFormInBackgroundThread"
event = "admin.FormBuilder.importFormFieldsInBackgroundThread"
, args = { formId=formId, xml=xml }
, runNow = true
, adminOwner = event.getAdminUserId()
Expand All @@ -890,21 +890,21 @@ component extends="preside.system.base.AdminHandler" {
, queryString = "taskId=" & taskId
) );
} catch ( any e ) {
messageBox.error( translateResource( uri="formbuilder:importForm.message.error" ) );
messageBox.error( translateResource( uri="formbuilder:importFormFields.message.error" ) );

setNextEvent( url=event.buildAdminLink( linkTo="formbuilder.importForm", queryString="id=#formId#" ), persistStruct=formData );
setNextEvent( url=event.buildAdminLink( linkTo="formbuilder.importFormFields", queryString="id=#formId#" ), persistStruct=formData );
}
}

private void function importFormInBackgroundThread( event, rc, prc, args={}, logger, progress ) {
private void function importFormFieldsInBackgroundThread( event, rc, prc, args={}, logger, progress ) {
var canProgress = StructKeyExists( arguments, "progress" );

var formId = args.formId ?: "";
var xml = args.xml ?: "";

logMessage( logger, "info", "Start importing the form fields and actions..." );
logMessage( logger, "info", "Start importing the form fields..." );

formBuilderService.importForm(
formBuilderService.importFormFields(
formId = formId
, xml = XmlParse( xml )
, logger = logger
Expand All @@ -918,8 +918,8 @@ component extends="preside.system.base.AdminHandler" {
logMessage( logger, "info", "Finished import." );
}

public string function exportFormAction( event, rc, prc, args ) {
var fileName = formBuilderService.exportForm( formId=rc.id ?: "" );
public string function exportFormFieldsAction( event, rc, prc, args ) {
var fileName = formBuilderService.exportFormFields( formId=rc.id ?: "" );

if ( isEmptyString( fileName ) ) {
event.notFound();
Expand Down
14 changes: 7 additions & 7 deletions system/i18n/formbuilder.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ question.not.found.alert=The question could not be found
manage.form.page.title=Manage form
manage.form.page.subtitle=Manage all aspects of the '{1}' form
manageform.breadcrumb.title={1}
manage.empty.form.notice=Your form is currently empty. Drag and drop form fields from the left menu to start to build your form.
manage.empty.form.notice=or, drag and drop form fields from the left menu to start to build your form.
manage.drag.new.items.instructions=Drag and drop form fields from the left menu to add them to your form
management.tabs.fields.title=Fields and layout
Expand Down Expand Up @@ -94,15 +94,15 @@ cloneForm.page.title=Clone form
cloneForm.save=Save
cloned.success.message=Form has been cloned successfully.
importForm.page.title=Import form
importForm.submit.title=Import
importForm.field.file.title=XML file
importForm.message.error=Unable to import the form.
importFormFields.page.title=Import form fields
importFormFields.submit.title=Import
importFormFields.field.file.title=Form fields XML
importFormFields.message.error=Unable to import the form fields.
importFormFields.workbench.button.title=Import fields...
task.form.delete.title=Delete form and all its data
action.submission.download.title=Download submissions
action.form.import.title=Import fields/ actions
action.form.export.title=Export fields/ actions
action.fields.export.title=Export fields
action.form.delete.title=Delete form
action.form.delete.prompt=delete this form AND all its data
36 changes: 3 additions & 33 deletions system/services/formbuilder/FormBuilderService.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -2117,7 +2117,7 @@ component {
return false;
}

public string function exportForm(
public string function exportFormFields(
required string formId
) {
var formbuilderForm = getForm( id=arguments.formId );
Expand Down Expand Up @@ -2189,39 +2189,19 @@ component {
ArrayAppend( xml.form.xmlChildren, xmlItems );
ArrayAppend( xml.form.xmlChildren, xmlQuestions );

// Actions
var formbuilderFormActions = _getActionsService().getFormActions( id=arguments.formId );
var actionsRoot = XmlElemNew( xml, "actions" );
for ( var formbuilderFormAction in formbuilderFormActions ) {
var action = XmlElemNew( xml, "action" );

StructAppend( action.xmlAttributes, {
id = formbuilderFormAction.id
, actionId = formbuilderFormAction.action.id
});

if ( !StructIsEmpty( formbuilderFormAction.configuration ) ) {
var config = XmlElemNew( xml, "config" );
StructAppend( config.xmlAttributes, formbuilderFormAction.configuration );
ArrayAppend( action.xmlChildren, config );
}

ArrayAppend( actionsRoot.xmlChildren, action );
}
ArrayAppend( xml.form.xmlChildren, actionsRoot );

FileWrite( "#getTempDirectory()#/#fileName#", ToString( xml ) );

return fileName;
}

public void function importForm(
public void function importFormFields(
required string formId
, required any xml
, any logger
, any progress
) {
var items = XmlSearch( arguments.xml, "/form/items/item" );

for ( var item in items ) {
var itemAttributes = item.xmlAttributes ?: {};
var itemConfiguration = item.config.xmlAttributes ?: {};
Expand Down Expand Up @@ -2270,16 +2250,6 @@ component {
}
}
}

var actions = XmlSearch( xml, "/form/actions/action" );
for ( var action in actions ) {
var actionAttributes = action.xmlAttributes ?: {};
var actionConfiguration = action.config.xmlAttributes ?: {};

_getActionsService().addAction( formId=arguments.formId, action=actionAttributes.actionId, configuration=actionConfiguration );

$helpers.logMessage( logger, "info", "Action: #actionAttributes.actionId# created." );
}
}

// PRIVATE HELPERS
Expand Down
17 changes: 13 additions & 4 deletions system/views/admin/formbuilder/_itemsManagement.cfm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<cfscript>
items = args.items ?: [];
formId = args.formId ?: "";
items = args.items ?: [];
</cfscript>

<cfoutput>
Expand All @@ -9,8 +10,16 @@
</cfloop>
</ul>
<div class="instructions<cfif !items.len()> empty</cfif>">
<p class="empty-notice">#translateResource( "formbuilder:manage.empty.form.notice")#</p>
<p class="not-empty-notice">#translateResource( "formbuilder:manage.drag.new.items.instructions")#</p>
<i class="fa fa-fw fa-lg fa-plus blue"></i>
<p class="empty-notice">
<a class="btn btn-info" href="#event.buildAdminLink( linkto="formbuilder.importFormFields", queryString="id=#formId#" )#">
<i class="fa fa-plus bigger-110"></i>
#translateResource( "formbuilder:importFormFields.workbench.button.title" )#
</a>
<br />
<br />
#translateResource( "formbuilder:manage.empty.form.notice" )#
</p>

<p class="not-empty-notice">#translateResource( "formbuilder:manage.drag.new.items.instructions" )#</p>
</div>
</cfoutput>
3 changes: 1 addition & 2 deletions system/views/admin/formbuilder/_statusControls.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@

<ul class="dropdown-menu pull-right" role="menu" aria-labelledby="dLabel">
<cfif canEdit>
<li><a href="#event.buildAdminLink( linkto="formbuilder.importForm", queryString="id=#formId#" )#"><i class="fa fa-fw fa-file-import"></i>&nbsp; #translateResource( "formbuilder:action.form.import.title" )#</a></li>
<li><a href="#event.buildAdminLink( linkto="formbuilder.exportFormAction", queryString="id=#formId#" )#"><i class="fa fa-fw fa-file-export"></i>&nbsp; #translateResource( "formbuilder:action.form.export.title" )#</a></li>
<li><a href="#event.buildAdminLink( linkto="formbuilder.exportFormFieldsAction", queryString="id=#formId#" )#"><i class="fa fa-fw fa-file-export"></i>&nbsp; #translateResource( "formbuilder:action.fields.export.title" )#</a></li>
</cfif>
<cfif canDelete>
<li class="divider"></li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
</cfscript>

<cfoutput>
<form id="formbuilder-import-form" class="form-horizontal" method="post" enctype="multipart/form-data" action="#event.buildAdminLink( linkTo='formbuilder.importFormAction' )#">
<form id="formbuilder-import-form" class="form-horizontal" method="post" enctype="multipart/form-data" action="#event.buildAdminLink( linkTo='formbuilder.importFormFieldsAction' )#">
<input type="hidden" name="id" value="#id#" />

#renderForm(
formName = "formbuilder.importForm"
, formId = "formbuilder-import-form"
formName = "formbuilder.importFormFields"
, formId = "formbuilder-import-form-fields"
, context = "admin"
, validationResult = validationResult
)#
Expand All @@ -21,7 +21,7 @@
#translateResource( "cms:sitetree.cancel.btn" )#
</a>

<button type="submit" name="_saveAction" value="publish" class="btn btn-warning">#translateResource( "formbuilder:importForm.submit.title" )#</button>
<button type="submit" name="_saveAction" value="publish" class="btn btn-warning">#translateResource( "formbuilder:importFormFields.submit.title" )#</button>
</div>
</div>
</form>
Expand Down

0 comments on commit 9a26064

Please sign in to comment.