本文整理汇总了PHP中FormResponse::add方法的典型用法代码示例。如果您正苦于以下问题:PHP FormResponse::add方法的具体用法?PHP FormResponse::add怎么用?PHP FormResponse::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FormResponse
的用法示例。
在下文中一共展示了FormResponse::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* Overloaded so that form error messages are displayed.
*
* @see OrderFormValidator::php()
* @see Form::validate()
*/
function validate()
{
if ($this->validator) {
$errors = $this->validator->validate();
if ($errors) {
if (Director::is_ajax() && $this->validator->getJavascriptValidationHandler() == 'prototype') {
FormResponse::status_message(_t('Form.VALIDATIONFAILED', 'Validation failed'), 'bad');
foreach ($errors as $error) {
FormResponse::add(sprintf("validationError('%s', '%s', '%s');\n", Convert::raw2js($error['fieldName']), Convert::raw2js($error['message']), Convert::raw2js($error['messageType'])));
}
} else {
$data = $this->getData();
$formError = array();
if ($formMessageType = $this->MessageType()) {
$formError['message'] = $this->Message();
$formError['messageType'] = $formMessageType;
}
// Load errors into session and post back
Session::set("FormInfo.{$this->FormName()}", array('errors' => $errors, 'data' => $data, 'formError' => $formError));
}
return false;
}
}
return true;
}
示例2: run
function run(DataObjectSet $pages)
{
$pageIDs = $pages->column('ID');
foreach ($pageIDs as $pageID) {
FormResponse::add("\$('Form_EditForm').reloadIfSetTo({$pageID});");
}
$this->batchaction($pages, 'batchApprove', _t('BatchApprovePages.APPROVED_PAGES', 'Approved %d pages, %d failures'));
return FormResponse::respond();
}
示例3: publish
public function publish($comment, $member, $notify)
{
if (!$member) {
$member = Member::currentUser();
}
// We have to mark as completed now, or we'll get
// recursion from SiteTreeCMSWorkflow::onAfterPublish.
$this->Status = 'Completed';
$this->PublisherID = $member->ID;
$this->write();
$page = $this->Page();
$page->doDeleteFromLive();
// @todo Coupling to UI :-(
FormResponse::add(LeftAndMain::deleteTreeNodeJS($page));
if ($notify) {
// notify
}
return _t('SiteTreeCMSWorkflow.PUBLISHMESSAGE', 'Published changes to live version. Emailed %s.');
}
示例4: checkFolder
function checkFolder()
{
if (!$this->RootFolderID) {
$galleries = Folder::findOrMake('image-gallery');
$galleries->Title = 'Image Gallery';
$galleries->write();
$folder = Folder::findOrMake('image-gallery/' . $this->URLSegment);
$folder->Title = $this->Title;
$folder->setName($this->Title);
$folder->write();
$this->RootFolderID = $folder->ID;
$this->write();
$this->requireDefaultAlbum();
FormResponse::add("\$( 'Form_EditForm' ).getPageFromServer( {$this->ID} );");
} else {
$this->RootFolder()->setName($this->Title);
$this->RootFolder()->write();
}
}
示例5: run
function run(DataObjectSet $pages)
{
$pageIDs = $pages->column('ID');
foreach ($pageIDs as $pageID) {
FormResponse::add("\$('Form_EditForm').reloadIfSetTo({$pageID});");
}
$count = array();
$count['PUBLISH_SUCCESS'] = $count['DELETE_SUCCESS'] = 0;
$count['PUBLISH_FAILURE'] = $count['DELETE_FAILURE'] = 0;
$arbitraryPage = $pages->First();
$arbitraryPage->invokeWithExtensions('onBeforeBatchPublish', $pages);
foreach ($pages as $page) {
$type = $page->openWorkflowRequest() instanceof WorkflowDeletionRequest ? 'DELETE' : 'PUBLISH';
if ($page->batchPublish()) {
$count[$type . '_SUCCESS']++;
// Now make sure the tree title is appropriately updated
$publishedRecord = DataObject::get_by_id('SiteTree', $page->ID);
if ($publishedRecord) {
$JS_title = Convert::raw2js($publishedRecord->TreeTitle());
FormResponse::add("\$('sitetree').setNodeTitle({$page->ID}, '{$JS_title}');");
}
} else {
$count[$type . '_FAILURE']++;
FormResponse::add("\$('sitetree').addNodeClassByIdx('{$page->ID}', 'failed');");
}
$page->destroy();
unset($page);
}
$arbitraryPage->invokeWithExtensions('onAfterBatchPublish', $pages);
$messages = array('PUBLISH_SUCCESS' => _t('BatchPublishPages.PUBLISH_SUCCESS', 'Published %d pages.'), 'PUBLISH_FAILURE' => _t('BatchPublishPages.PUBLISH_FAILURE', 'Failed to publish %d pages.'), 'DELETE_SUCCESS' => _t('BatchPublishPages.DELETE_SUCCESS', 'Deleted %d pages from the published site.'), 'DELETE_FAILURE' => _t('BatchPublishPages.DELETE_FAILURE', 'Failed to delete %d pages from the published site.'), 'PUBLISH_SUCCESS_ONE' => _t('BatchPublishPages.PUBLISH_SUCCESS_ONE', 'Published %d page.'), 'PUBLISH_FAILURE_ONE' => _t('BatchPublishPages.PUBLISH_FAILURE_ONE', 'Failed to publish %d page.'), 'DELETE_SUCCESS_ONE' => _t('BatchPublishPages.DELETE_SUCCESS_ONE', 'Deleted %d page from the published site.'), 'DELETE_FAILURE_ONE' => _t('BatchPublishPages.DELETE_FAILURE_ONE', 'Failed to delete %d page from the published site.'));
$displayedMessages = array();
foreach ($count as $type => $count) {
if ($count) {
$message = $count == 1 ? $messages[$type . '_ONE'] : $messages[$type];
$displayedMessages[] = sprintf($message, $count);
}
}
$displayedMessage = implode(" ", $displayedMessages);
FormResponse::add('statusMessage("' . $displayedMessage . '","good");');
return FormResponse::respond();
}
示例6: moderate
function moderate()
{
$id = (int) $this->urlParams['ID'];
$className = Convert::raw2sql($this->urlParams['ClassName']);
$state = Convert::raw2sql($this->urlParams['State']);
$methods = array("delete" => "moderatorDelete", "isspam" => "markSpam", "isham" => "markHam", "approve" => "markApproved", "unapprove" => "markUnapproved");
ModeratableState::push_state($state);
$method = $methods[$this->urlParams['Command']];
if (!$method) {
FormResponse::clear();
FormResponse::status_message("Command invalid", 'bad');
} else {
if ($error = DataObject::get_by_id($className, $id)->{$method}()) {
FormResponse::status_message($error, 'bad');
} else {
FormResponse::add('$("moderation").elementMoved(' . $id . ');');
}
}
ModeratableState::pop_state();
return FormResponse::respond();
}
示例7: returnItemToUser
/**
* Allows you to returns a new data object to the tree (subclass of sitetree)
* and updates the tree via javascript.
*/
public function returnItemToUser($p)
{
if (Director::is_ajax()) {
// Prepare the object for insertion.
$parentID = (int) $p->ParentID;
$id = $p->ID ? $p->ID : "new-{$p->class}-{$p->ParentID}";
$treeTitle = Convert::raw2js($p->TreeTitle());
$hasChildren = is_numeric($id) && $p->AllChildren() && $p->AllChildren()->Count() ? ' unexpanded' : '';
// Ensure there is definitly a node avaliable. if not, append to the home tree.
$response = <<<JS
\t\t\t\tvar tree = \$('sitetree');
\t\t\t\tvar newNode = tree.createTreeNode("{$id}", "{$treeTitle}", "{$p->class}{$hasChildren}");
\t\t\t\tnode = \$('record-0');
\t\t\t\tnode.open();
\t\t\t\tnode.appendTreeNode(newNode);
\t\t\t\tnewNode.selectTreeNode();
JS;
FormResponse::add($response);
FormResponse::load_form($this->getitem(), 'Form_EditForm');
return FormResponse::respond();
} else {
Director::redirect('admin/' . self::$url_segment . '/show/' . $p->ID);
}
}
示例8: createtranslation
/**
* Create a new translation from an existing item, switch to this language and reload the tree.
*/
function createtranslation () {
if(!Director::is_ajax()) {
Director::redirectBack();
return;
}
$langCode = $_REQUEST['newlang'];
$langName = i18n::get_language_name($langCode);
$originalLangID = $_REQUEST['ID'];
$record = $this->getRecord($originalLangID);
$temporalID = "new-$record->RecordClassName-$record->ParentID-$originalLangID";
Session::set($temporalID . '_originalLangID',$originalLangID);
$tree = $this->switchlanguage($langCode, $originalLangID);
FormResponse::add(<<<JS
if (Element.hasClassName('LangSelector_holder','onelang')) {
Element.removeClassName('LangSelector_holder','onelang');
$('treepanes').resize();
}
if ($('LangSelector').options['$langCode'] == undefined) {
var option = document.createElement("option");
option.text = '$langName';
option.value = '$langCode';
$('LangSelector').options.add(option);
}
JS
);
FormResponse::add("$('LangSelector').selectValue('$langCode');");
$newrecord = clone $record;
$newrecord->ID = $temporalID;
return $this->returnItemToUser($newrecord);
}
示例9: createtranslation
/**
* Create a new translation from an existing item, switch to this language and reload the tree.
*/
function createtranslation($request)
{
// Protect against CSRF on destructive action
if (!SecurityToken::inst()->checkRequest($request)) {
return $this->httpError(400);
}
$langCode = Convert::raw2sql($_REQUEST['newlang']);
$originalLangID = (int) $_REQUEST['ID'];
$record = $this->getRecord($originalLangID);
$this->Locale = $langCode;
Translatable::set_current_locale($langCode);
// Create a new record in the database - this is different
// to the usual "create page" pattern of storing the record
// in-memory until a "save" is performed by the user, mainly
// to simplify things a bit.
// @todo Allow in-memory creation of translations that don't persist in the database before the user requests it
$translatedRecord = $record->createTranslation($langCode);
$url = sprintf("%s/%d/?locale=%s", $this->Link('show'), $translatedRecord->ID, $langCode);
FormResponse::add(sprintf('window.location.href = "%s";', $url));
return FormResponse::respond();
}
示例10: workflowAction
/**
* Process a workflow action.
* @param string $workflowClass The sub-class of WorkflowRequest that is expected.
* @param string $actionName The action method to call on the given WorkflowRequest objec.t
* @param int $id The ID# of the page.
* @param string $comment The comment to attach.
* @param string $successMessage The message to show on success.
*/
function workflowAction($workflowClass, $actionName, $id, $comment)
{
if (is_numeric($id)) {
// For 2.3 and 2.4 compatibility
$bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`";
$page = DataObject::get_by_id("SiteTree", $id);
if (!$page) {
$page = Versioned::get_one_by_stage("SiteTree", "Live", "{$bt}SiteTree{$bt}.{$bt}ID{$bt} = {$id}");
}
if (!$page) {
return new HTTPResponse("Can't find Page #{$id}", 400);
}
} else {
return new HTTPResponse("Bad ID", 400);
}
// If we are creating and approving a workflow in one step, then don't bother emailing
$notify = !($actionName == 'action' && !$page->openWorkflowRequest($workflowClass));
if ($request = $page->openOrNewWorkflowRequest($workflowClass, $notify)) {
$request->clearMembersEmailed();
if ($successMessage = $request->{$actionName}($comment, null, $notify)) {
FormResponse::get_page($id);
$title = Convert::raw2js($page->TreeTitle());
FormResponse::add("\$('sitetree').setNodeTitle({$id}, \"{$title}\");");
// gather members for status output
if ($notify) {
$peeps = $request->getMembersEmailed();
if ($peeps && $peeps->Count()) {
$emails = '';
foreach ($peeps as $peep) {
if ($peep->Email) {
$emails .= $peep->Email . ', ';
}
}
$emails = trim($emails, ', ');
} else {
$emails = 'no-one';
}
} else {
$emails = "no-one";
}
if ($successMessage) {
FormResponse::status_message(sprintf($successMessage, $emails), 'good');
return FormResponse::respond();
} else {
return;
}
}
}
// Failure
FormResponse::status_message(_t('SiteTreeCMSWorkflow.WORKFLOW_ACTION_FAILED', "There was an error when processing your workflow request."), 'bad');
return FormResponse::respond();
}
示例11: FieldHolder
/**
* @return String
*/
function FieldHolder()
{
// set caption if required
if ($this->popupCaption) {
$id = $this->id();
if (Director::is_ajax()) {
$js = <<<JS
\$('{$id}').GB_Caption = '{$this->popupCaption}';
JS;
FormResponse::add($js);
} else {
$js = <<<JS
Event.observe(window, 'load', function() { \$('{$id}').GB_Caption = '{$this->popupCaption}'; });
JS;
Requirements::customScript($js);
}
}
// compute sourceItems here instead of Items() to ensure that
// pagination and filters are respected on template accessors
$this->sourceItems();
return $this->renderWith($this->template);
}
示例12: publish
public function publish($comment, $member, $notify)
{
if (!$member) {
$member = Member::currentUser();
}
// We have to mark as completed now, or we'll get
// recursion from SiteTreeCMSWorkflow::onAfterPublish.
$page = $this->Page();
$page->LatestCompletedWorkflowRequestID = $this->ID;
$page->writeWithoutVersion();
// Embargo means we go Approved -> Scheduled
if ($this->EmbargoDate) {
$this->setSchedule();
$this->PublisherID = $member->ID;
$this->write();
// Otherwise we go Approved -> Published
} else {
$this->Status = 'Completed';
$this->PublisherID = $member->ID;
$this->write();
// Only publish the page if it hasn't already been published elsewhere. This occurs when
// SiteTree::doPublish() 'auto-closes' an open workflow
//if($page->getIsModifiedOnStage()) {
$page->doPublish();
//}
if ($notify) {
$this->notifyPublished($comment);
}
}
$this->addNewChange($comment, $this->Status, DataObject::get_by_id('Member', $this->PublisherID));
// @todo Coupling to UI :-(
$title = Convert::raw2js($page->TreeTitle());
FormResponse::add("\$('sitetree').setNodeTitle({$page->ID}, \"{$title}\");");
return _t('SiteTreeCMSWorkflow.PUBLISHMESSAGE', 'Published changes to live version. Emailed %s.');
}
示例13: run
function run(DataObjectSet $pages)
{
foreach ($pages as $page) {
$id = $page->ID;
// Perform the action
if ($page->canDelete()) {
$page->doDeleteFromLive();
}
// check to see if the record exists on the live site, if it doesn't remove the tree node
$stageRecord = Versioned::get_one_by_stage('SiteTree', 'Stage', "`SiteTree`.`ID`={$id}");
if ($stageRecord) {
$stageRecord->IsAddedToStage = true;
$title = Convert::raw2js($stageRecord->TreeTitle());
FormResponse::add("\$('sitetree').setNodeTitle({$id}, '{$title}');");
FormResponse::add("\$('Form_EditForm').reloadIfSetTo({$id});");
} else {
FormResponse::add("var node = \$('sitetree').getTreeNodeByIdx('{$id}');");
FormResponse::add("if(node && node.parentTreeNode)\tnode.parentTreeNode.removeTreeNode(node);");
FormResponse::add("\$('Form_EditForm').reloadIfSetTo({$id});");
}
$page->destroy();
unset($page);
}
$message = sprintf(_t('CMSBatchActions.DELETED_PAGES', 'Deleted %d pages from the published site'), $pages->Count());
FormResponse::add('statusMessage("' . $message . '","good");');
return FormResponse::respond();
}
示例14: deleteitems
/**
* Delete a number of items
*/
public function deleteitems($request)
{
// Protect against CSRF on destructive action
if (!SecurityToken::inst()->checkRequest($request)) {
return $this->httpError(400);
}
$ids = split(' *, *', $_REQUEST['csvIDs']);
$script = "st = \$('sitetree'); \n";
foreach ($ids as $id) {
if (is_numeric($id)) {
$record = DataObject::get_by_id($this->stat('tree_class'), $id);
if ($record && !$record->canDelete()) {
return Security::permissionFailure($this);
}
DataObject::delete_by_id($this->stat('tree_class'), $id);
$script .= "node = st.getTreeNodeByIdx({$id}); if(node) node.parentTreeNode.removeTreeNode(node); \$('Form_EditForm').closeIfSetTo({$id}); \n";
}
}
FormResponse::add($script);
return FormResponse::respond();
}
示例15: deleteitems
/**
* Delete a number of items
*/
public function deleteitems()
{
$ids = split(' *, *', $_REQUEST['csvIDs']);
$script = "st = \$('sitetree'); \n";
foreach ($ids as $id) {
if (is_numeric($id)) {
DataObject::delete_by_id($this->stat('tree_class'), $id);
$script .= "node = st.getTreeNodeByIdx({$id}); if(node) node.parentTreeNode.removeTreeNode(node); \$('Form_EditForm').closeIfSetTo({$id}); \n";
}
}
FormResponse::add($script);
return FormResponse::respond();
}