* story: remove custom submit function and submit form by ajax-form.
This commit is contained in:
@@ -18,75 +18,24 @@ $(function()
|
||||
}
|
||||
});
|
||||
|
||||
window.customSubmit = function(e)
|
||||
window.clickSubmit = function(e)
|
||||
{
|
||||
const $saveButton = $('#saveButton');
|
||||
const $saveDraftButton = $('#saveDraftButton');
|
||||
const status = $(e.submitter).data('status');
|
||||
if(status === undefined) return;
|
||||
|
||||
$saveButton.attr('disabled', 'disabled');
|
||||
$saveDraftButton.attr('disabled', 'disabled');
|
||||
|
||||
var $dataform = $('#dataform');
|
||||
var $this = $(e.target);
|
||||
if($this.prop('tagName') != 'BUTTON') $this = $this.closest('button');
|
||||
|
||||
var storyStatus = 'active';
|
||||
if(!$dataform.hasClass('form-batch')) storyStatus = !$('[name^=reviewer]').val() || $('#needNotReview').prop('checked') ? 'active' : 'reviewing';
|
||||
if($this.attr('id') == 'saveDraftButton')
|
||||
const method = config.currentMethod;
|
||||
let storyStatus = status;
|
||||
if(status == 'active' && method != 'batchcreate')
|
||||
{
|
||||
storyStatus = 'draft';
|
||||
if(config.currentMethod == 'change') storyStatus = 'changing';
|
||||
if(config.currentMethod == 'edit' && $('#status').val() == 'changing') storyStatus = 'changing';
|
||||
storyStatus = !$('[name^=reviewer]').val() || $('#needNotReview').prop('checked') ? 'active' : 'reviewing';
|
||||
}
|
||||
if($('#dataform #status').length == 0) $('<input />').attr('type', 'hidden').attr('name', 'status').attr('id', 'status').attr('value', storyStatus).appendTo('#dataform .form-actions');
|
||||
$('#dataform #status').val(storyStatus);
|
||||
|
||||
$.ajaxSubmit(
|
||||
if(status == 'draft' && (method == 'change' || (method == 'edit' && $('#status').val() == 'changing')))
|
||||
{
|
||||
headers: $this.closest('.modal').length > 0 ? {'X-Zui-Modal': 'modal'} : {},
|
||||
data: new FormData($dataform[0]),
|
||||
url: $dataform.attr('action'),
|
||||
onSuccess: function(result) {loadPage(result.load)},
|
||||
onMessage: function(message) {showMessage(message)},
|
||||
onFail: function(result)
|
||||
{
|
||||
setTimeout(function()
|
||||
{
|
||||
$saveButton.removeAttr('disabled');
|
||||
$saveDraftButton.removeAttr('disabled');
|
||||
}, 500);
|
||||
},
|
||||
});
|
||||
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
||||
setTimeout(function()
|
||||
{
|
||||
$saveButton.removeAttr('disabled');
|
||||
$saveDraftButton.removeAttr('disabled');
|
||||
}, 10000);
|
||||
storyStatus = 'changing';
|
||||
}
|
||||
$(e.submitter).closest('form').find('[name=status]').val(storyStatus);
|
||||
};
|
||||
|
||||
function showMessage(message)
|
||||
{
|
||||
var varType = typeof message;
|
||||
if(varType === 'object')
|
||||
{
|
||||
for(id in message)
|
||||
{
|
||||
var $this = $('#' + id);
|
||||
if($this.length == 0) return zui.Messager.show({"content": message[id], "type": "success circle"});
|
||||
|
||||
$('#' + id + 'Tip').remove();
|
||||
$this.addClass('has-error');
|
||||
$this.parent().after("<div class='form-tip ajax-form-tip text-danger' id='" + id + "Tip'>" + message[id] + '</div>');
|
||||
document.getElementById(id).focus();
|
||||
}
|
||||
}
|
||||
if(varType === 'string') zui.Messager.show({"content": message, "type": "success circle"});
|
||||
}
|
||||
|
||||
window.unlinkTwins = function(e)
|
||||
{
|
||||
const $this = $(e.target).closest('li').find('.relievedTwins');
|
||||
|
||||
@@ -42,10 +42,9 @@ $fnGenerateFields = function() use ($lang, $fields, $stories)
|
||||
|
||||
formBatchPanel
|
||||
(
|
||||
on::click('#saveButton', 'customSubmit'),
|
||||
on::click('#saveDraftButton', 'customSubmit'),
|
||||
setID('dataform'),
|
||||
$stories ? set::data($stories) : null,
|
||||
set::ajax(array('beforeSubmit' => jsRaw('clickSubmit'))),
|
||||
set::title($storyID ? $storyTitle . $lang->colon . $this->lang->story->subdivide : $this->lang->story->batchCreate),
|
||||
set::uploadParams('module=story¶ms=' . helper::safe64Encode("productID=$productID&branch=$branch&moduleID=$moduleID&storyID=$storyID&executionID=$executionID&plan=&type=$type")),
|
||||
set::pasteField('title'),
|
||||
@@ -53,11 +52,12 @@ formBatchPanel
|
||||
set::items($fnGenerateFields()),
|
||||
set::actions(array
|
||||
(
|
||||
array('text' => $lang->save, 'id' => 'saveButton', 'class' => 'primary'),
|
||||
array('text' => $lang->story->saveDraft, 'id' => 'saveDraftButton', 'class' => 'secondary'),
|
||||
array('text' => $lang->goback, 'data-back' => 'APP', 'class' => 'open-url')
|
||||
array('text' => $lang->save, 'data-status' => 'active', 'class' => 'primary', 'btnType' => 'submit'),
|
||||
array('text' => $lang->story->saveDraft, 'data-status' => 'draft', 'class' => 'secondary', 'btnType' => 'submit'),
|
||||
array('text' => $lang->goback, 'data-back' => 'APP', 'class' => 'open-url')
|
||||
)),
|
||||
formHidden('type', $type)
|
||||
formHidden('type', $type),
|
||||
formHidden('status')
|
||||
);
|
||||
|
||||
render();
|
||||
|
||||
@@ -171,23 +171,18 @@ $formItems['file'] = formGroup
|
||||
);
|
||||
if($this->config->vision != 'or') $formItems['affected'] = $getAffectedTabs($story, $users);
|
||||
|
||||
$formActions = formRow
|
||||
(
|
||||
setClass('form-actions form-group no-label'),
|
||||
btn(setClass('primary'), setID('saveButton'), $lang->save),
|
||||
btn(setClass('secondary'), setID('saveDraftButton'), $lang->story->doNotSubmit),
|
||||
backBtn($lang->goback)
|
||||
);
|
||||
|
||||
formPanel
|
||||
(
|
||||
on::click('#saveButton', 'customSubmit'),
|
||||
on::click('#saveDraftButton', 'customSubmit'),
|
||||
setID('dataform'),
|
||||
set::actions(false),
|
||||
set::ajax(array('beforeSubmit' => jsRaw('clickSubmit'))),
|
||||
set::actions(array
|
||||
(
|
||||
array('text' => $lang->save, 'data-status' => 'active', 'class' => 'primary', 'btnType' => 'submit'),
|
||||
array('text' => $lang->story->doNotSubmit, 'data-status' => 'draft', 'class' => 'secondary', 'btnType' => 'submit'),
|
||||
array('text' => $lang->goback, 'data-back' => 'APP', 'class' => 'open-url')
|
||||
)),
|
||||
$formTitle,
|
||||
$formItems,
|
||||
$formActions,
|
||||
h::hr(),
|
||||
history()
|
||||
);
|
||||
|
||||
@@ -22,9 +22,8 @@ jsVar('branchCount', isset($fields['branches']['options']) ? count($fields['bran
|
||||
|
||||
formPanel
|
||||
(
|
||||
commonModel::isTutorialMode() ? '' : on::click('#saveButton', 'customSubmit'),
|
||||
on::click('#saveDraftButton', 'customSubmit'),
|
||||
setID('dataform'),
|
||||
set::ajax(array('beforeSubmit' => jsRaw('clickSubmit'))),
|
||||
to::heading(div
|
||||
(
|
||||
setClass('panel-title text-lg'),
|
||||
@@ -33,9 +32,9 @@ formPanel
|
||||
)),
|
||||
set::actions(array
|
||||
(
|
||||
array('text' => $lang->save, 'id' => 'saveButton', 'class' => 'primary'),
|
||||
array('text' => $lang->story->saveDraft, 'id' => 'saveDraftButton', 'class' => 'secondary'),
|
||||
array('text' => $lang->goback, 'data-back' => 'APP', 'class' => 'open-url')
|
||||
array('text' => $lang->save, 'data-status' => 'active', 'class' => 'primary', 'btnType' => 'submit'),
|
||||
array('text' => $lang->story->saveDraft, 'data-status' => 'draft', 'class' => 'secondary', 'btnType' => 'submit'),
|
||||
array('text' => $lang->goback, 'data-back' => 'APP', 'class' => 'open-url')
|
||||
)),
|
||||
set::customFields(true),
|
||||
formRow
|
||||
|
||||
@@ -67,10 +67,11 @@ detailBody
|
||||
(
|
||||
setID('dataform'),
|
||||
set::isForm(true),
|
||||
set::ajax(array('beforeSubmit' => jsRaw('clickSubmit'))),
|
||||
$canEditContent ? set::actions(array
|
||||
(
|
||||
array('tag' => 'button', 'class' => 'primary', 'id' => 'saveButton', 'data-on' => 'click', 'data-call' => 'customSubmit', 'data-params' => 'event', 'text' => $lang->save),
|
||||
array('tag' => 'button', 'class' => 'secondary', 'id' => 'saveDraftButton', 'data-on' => 'click', 'data-call' => 'customSubmit', 'data-params' => 'event', 'text' => $story->status == 'changing' ? $lang->story->doNotSubmit : $lang->story->saveDraft),
|
||||
array('btnType' => 'submit', 'class' => 'primary', 'data-status' => 'active', 'text' => $lang->save),
|
||||
array('btnType' => 'submit', 'class' => 'secondary', 'data-status' => 'draft', 'text' => $story->status == 'changing' ? $lang->story->doNotSubmit : $lang->story->saveDraft),
|
||||
isInModal() ? null : array('text' => $lang->goback, 'back' => 'APP')
|
||||
)) : null,
|
||||
sectionList
|
||||
|
||||
Reference in New Issue
Block a user