/**
  * Includes the dependency if necessary, applies the Bootstrap templates,
  * and renders the form HTML output
  *
  * @return string
  */
 public function forTemplate()
 {
     $this->Fields()->bootstrapify();
     $this->Actions()->bootstrapify();
     Requirements::css(FOUNDATIONFORMS_DIR . '/css/foundationforms.css');
     return parent::forTemplate();
 }
 public function forTemplate()
 {
     // Keep session alive if there is a logged in member
     if ($this->keepSessionAlive && Member::currentUserID()) {
         Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/ping.js');
     }
     return parent::forTemplate();
 }
 /**
  * Save the current sites {@link SiteConfig} into the database
  *
  * @param array $data 
  * @param Form $form 
  * @return String
  */
 function save_siteconfig($data, $form)
 {
     $siteConfig = SiteConfig::current_site_config();
     $form->saveInto($siteConfig);
     $siteConfig->write();
     $this->response->addHeader('X-Status', rawurlencode(_t('LeftAndMain.SAVEDUP', 'Saved.')));
     return $form->forTemplate();
 }
Example #4
0
	function forTemplate() {
		$ret = parent::forTemplate();
		
		Requirements::css(FRAMEWORK_DIR . '/css/ComplexTableField_popup.css');
		Requirements::javascript(FRAMEWORK_DIR . "/thirdparty/prototype/prototype.js");
		Requirements::javascript(FRAMEWORK_DIR . "/thirdparty/behaviour/behaviour.js");
		Requirements::javascript(FRAMEWORK_DIR . "/thirdparty/scriptaculous/scriptaculous.js");
		Requirements::javascript(FRAMEWORK_DIR . "/thirdparty/scriptaculous/scriptaculous/controls.js");
		Requirements::add_i18n_javascript(FRAMEWORK_DIR . '/javascript/lang');
		Requirements::javascript(FRAMEWORK_DIR . "/javascript/ComplexTableField_popup.js");

		// Append requirements from instance callbacks
		$parent = $this->getParentController();
		if($parent instanceof ComplexTableField) {
			$callback = $parent->requirementsForPopupCallback;
		} else {
			$callback = $parent->getParentController()->requirementsForPopupCallback;
		}
		if($callback) call_user_func($callback, $this);
		
		return $ret;
	}
 function forTemplate()
 {
     $ret = parent::forTemplate();
     /**
      * WARNING: DO NOT CHANGE THE ORDER OF THESE JS FILES
      * Some have special requirements.
      */
     Requirements::css(SAPPHIRE_DIR . '/css/Form.css');
     Requirements::css(SAPPHIRE_DIR . '/css/ComplexTableField_popup.css');
     Requirements::css(CMS_DIR . '/css/typography.css');
     Requirements::css(CMS_DIR . '/css/cms_right.css');
     Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/prototype/prototype.js");
     Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/behaviour/behaviour.js");
     Requirements::javascript(SAPPHIRE_DIR . "/javascript/prototype_improvements.js");
     Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/scriptaculous/scriptaculous.js");
     Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/scriptaculous/scriptaculous/controls.js");
     Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
     Requirements::javascript(SAPPHIRE_DIR . "/javascript/ComplexTableField_popup.js");
     // Append requirements from instance callbacks
     $parent = $this->getParentController();
     if ($parent instanceof ComplexTableField) {
         $callback = $parent->requirementsForPopupCallback;
     } else {
         $callback = $parent->getParentController()->requirementsForPopupCallback;
     }
     if ($callback) {
         call_user_func($callback, $this);
     }
     // Append requirements from DataObject
     // DEPRECATED 2.4 Use ComplexTableField->requirementsForPopupCallback
     if ($this->dataObject->hasMethod('getRequirementsForPopup')) {
         $this->dataObject->getRequirementsForPopup();
     }
     return $ret;
 }
 /**
  * This is the action that gets executed when a GridField_AlterAction gets clicked.
  *
  * @param array $data
  * @param Form $form
  * @param SS_HTTPRequest $request
  *
  * @return string
  */
 public function gridFieldAlterAction($data, $form, SS_HTTPRequest $request)
 {
     $data = $request->requestVars();
     // Protection against CSRF attacks
     $token = $this->getForm()->getSecurityToken();
     if (!$token->checkRequest($request)) {
         $this->httpError(400, _t("Form.CSRF_FAILED_MESSAGE", "There seems to have been a technical problem. Please click the back button, " . "refresh your browser, and try again."));
     }
     $name = $this->getName();
     $fieldData = null;
     if (isset($data[$name])) {
         $fieldData = $data[$name];
     }
     $state = $this->getState(false);
     if (isset($fieldData['GridState'])) {
         $state->setValue($fieldData['GridState']);
     }
     foreach ($data as $dataKey => $dataValue) {
         if (preg_match('/^action_gridFieldAlterAction\\?StateID=(.*)/', $dataKey, $matches)) {
             $stateChange = Session::get($matches[1]);
             $actionName = $stateChange['actionName'];
             $arguments = array();
             if (isset($stateChange['args'])) {
                 $arguments = $stateChange['args'];
             }
             $html = $this->handleAlterAction($actionName, $arguments, $data);
             if ($html) {
                 return $html;
             }
         }
     }
     if ($request->getHeader('X-Pjax') === 'CurrentField') {
         return $this->FieldHolder();
     }
     return $form->forTemplate();
 }
 /**
  * Return the form to the user if it exists, otherwise some information
  * about who is currently editing
  * 
  * @return Form
  */
 public function Form()
 {
     // The editing form hasn't been put in place by the 'edit' action
     // so lets just show the status form
     $append = '';
     if (!$this->form) {
         if (WikiPage::$show_edit_button || $this->data()->canEdit()) {
             // create the information form
             $this->form = $this->StatusForm();
         }
     } else {
         // if we have got an editing form, then we'll add a New Page
         // form if we have permissions to do so
         if (Permission::check(MANAGE_WIKI_PAGES)) {
             $append = $this->CreatePageForm()->forTemplate();
         }
     }
     return $this->form->forTemplate() . $append;
 }
Example #8
0
 /**
  * This is the action that gets executed when a GridField_AlterAction gets clicked.
  *
  * @param array $data
  * @param Form $form
  * @param SS_HTTPRequest $request
  *
  * @return string
  */
 public function gridFieldAlterAction($data, $form, SS_HTTPRequest $request)
 {
     $data = $request->requestVars();
     $name = $this->getName();
     $fieldData = null;
     if (isset($data[$name])) {
         $fieldData = $data[$name];
     }
     $state = $this->getState(false);
     if (isset($fieldData['GridState'])) {
         $state->setValue($fieldData['GridState']);
     }
     foreach ($data as $dataKey => $dataValue) {
         if (preg_match('/^action_gridFieldAlterAction\\?StateID=(.*)/', $dataKey, $matches)) {
             $stateChange = Session::get($matches[1]);
             $actionName = $stateChange['actionName'];
             $arguments = array();
             if (isset($stateChange['args'])) {
                 $arguments = $stateChange['args'];
             }
             $html = $this->handleAlterAction($actionName, $arguments, $data);
             if ($html) {
                 return $html;
             }
         }
     }
     if ($request->getHeader('X-Pjax') === 'CurrentField') {
         return $this->FieldHolder();
     }
     return $form->forTemplate();
 }
 /**
  * This method tries to blend DetailForm::doSave behaviour with CMSMain
  * publish behaviour. It might not be rock solid..
  *
  * @param array $data
  * @param Form $form
  * @return SS_HTTPResponse
  */
 public function publish($data, $form)
 {
     if (!$this->record->canPublish()) {
         return $controller->httpError(403);
     }
     $controller = Controller::curr();
     $list = $this->gridField->getList();
     if ($list instanceof ManyManyList) {
         // Data is escaped in ManyManyList->add()
         $extraData = isset($data['ManyMany']) ? $data['ManyMany'] : null;
     } else {
         $extraData = null;
     }
     try {
         $this->record->writeWithoutVersion();
         $form->saveInto($this->record);
         $this->record->write();
         $list->add($this->record, $extraData);
         $this->record->doPublish();
     } catch (ValidationException $e) {
         $form->sessionMessage($e->getResult()->message(), 'bad');
         $responseNegotiator = new PjaxResponseNegotiator(array('CurrentForm' => function () use(&$form) {
             return $form->forTemplate();
         }, 'default' => function () use(&$controller) {
             return $controller->redirectBack();
         }));
         if ($controller->getRequest()->isAjax()) {
             $controller->getRequest()->addHeader('X-Pjax', 'CurrentForm');
         }
         return $responseNegotiator->respond($controller->getRequest());
     }
     $link = '"' . $this->record->Title . '"';
     $message = _t('GridFieldDetailForm.Saved', 'Saved {name} {link}', array('name' => $this->record->i18n_singular_name(), 'link' => $link));
     $form->sessionMessage($message, 'good');
     return $this->edit(Controller::curr()->getRequest());
 }
 /**
  * Includes the dependency if necessary, applies the Bootstrap templates,
  * and renders the form HTML output
  *
  * @return string
  */
 public function forTemplate()
 {
     $this->transform(new FoundationFormTransformation());
     $this->addExtraClass('custom');
     return parent::forTemplate();
 }
 /**
  * @param array $data
  * @param Form $form
  * @param SS_HTTPRequest $request
  * @return HTML|HTMLText|mixed
  */
 public function gridFieldAlterAction($data, $form, SS_HTTPRequest $request)
 {
     $data = $request->requestVars();
     $stateHash = $this->getStateHash();
     // Check if we have encountered a reset action. We need to clear the state here before
     // the other components start accessing it.
     foreach ($data as $dataKey => $dataValue) {
         if (preg_match('/^action_gridFieldAlterAction\\?StateID=(.*)/', $dataKey, $matches)) {
             $stateChange = Session::get($matches[1]);
             $actionName = $stateChange['actionName'];
             if ($actionName === 'ResetState') {
                 Session::set($stateHash, null);
                 $this->state = new GridState($this);
             }
         }
     }
     foreach ($data as $dataKey => $dataValue) {
         if (preg_match('/^action_gridFieldAlterAction\\?StateID=(.*)/', $dataKey, $matches)) {
             $stateChange = Session::get($matches[1]);
             $actionName = $stateChange['actionName'];
             $arguments = array();
             if (isset($stateChange['args'])) {
                 $arguments = $stateChange['args'];
             }
             $html = $this->handleAlterAction($actionName, $arguments, $data);
             if ($html) {
                 return $html;
             }
         }
     }
     // The state is stored in the session so that we can access it on the next page load
     $this->setStateHash($this->state->Value());
     if ($request->getHeader('X-Pjax') === 'CurrentField') {
         return $this->FieldHolder();
     }
     return $form->forTemplate();
 }
 /**
  * Save the current sites {@link SiteConfig} into the database.
  *
  * @param array $data 
  * @param Form $form 
  * @return String
  */
 public function save_siteconfig($data, $form)
 {
     $siteConfig = SiteConfig::current_site_config();
     $form->saveInto($siteConfig);
     try {
         $siteConfig->write();
     } catch (ValidationException $ex) {
         $form->sessionMessage($ex->getResult()->message(), 'bad');
         return $this->getResponseNegotiator()->respond($this->request);
     }
     $this->response->addHeader('X-Status', rawurlencode(_t('LeftAndMain.SAVEDUP', 'Saved.')));
     return $form->forTemplate();
 }
 /**
  * Generate a response object for a form validation error
  *
  * @param Form $form The source form
  * @param ValidationException $e The validation error message
  * @return SS_HTTPResponse
  * @throws SS_HTTPResponse_Exception
  */
 protected function generateValidationResponse($form, $e)
 {
     $controller = $this->getToplevelController();
     $form->sessionMessage($e->getResult()->message(), 'bad', false);
     $responseNegotiator = new PjaxResponseNegotiator(array('CurrentForm' => function () use(&$form) {
         return $form->forTemplate();
     }, 'default' => function () use(&$controller) {
         return $controller->redirectBack();
     }));
     if ($controller->getRequest()->isAjax()) {
         $controller->getRequest()->addHeader('X-Pjax', 'CurrentForm');
     }
     return $responseNegotiator->respond($controller->getRequest());
 }
 /**
  * Includes the dependency if necessary, applies the Bootstrap templates,
  * and renders the form HTML output
  *
  * @return string
  */
 public function forTemplate()
 {
     if (!$this->stat('bootstrap_included')) {
         Requirements::css(BOOTSTRAP_FORMS_DIR . '/css/bootstrap.css');
     }
     if (!$this->stat('jquery_included')) {
         Requirements::javascript(THIRDPARTY_DIR . "/jquery/jquery.js");
     }
     if (!$this->stat('bootstrap_form_included')) {
         Requirements::javascript(BOOTSTRAP_FORMS_DIR . "/javascript/bootstrap_forms.js");
     }
     $this->addExtraClass("form-{$this->formLayout}");
     $this->applyBootstrap();
     return parent::forTemplate();
 }
Example #15
0
 function MiddleContent()
 {
     $ret = '';
     if (isset($_GET['currentMethod']) && $_GET['currentMethod'] && isset($_GET['currentForm']) && $_GET['currentForm']) {
         $className = $_GET['currentMethod'];
         $payment = singleton($className);
         $form = $payment->getForm($_GET['currentForm']);
         $form->setFormAction($this->FormActionLink("HarnessForm"));
     } else {
         $message = "Click on a testable payment method that you want to test on";
         $form = new Form($this, 'HarnessForm', new FieldSet(), new FieldSet());
         $form->sessionMessage($message, 'bad');
     }
     return $form->forTemplate();
 }
 function forTemplate()
 {
     $ret = parent::forTemplate();
     /**
      * WARNING: DO NOT CHANGE THE ORDER OF THESE JS FILES
      * Some have special requirements.
      */
     Requirements::css(SAPPHIRE_DIR . '/css/Form.css');
     Requirements::css(SAPPHIRE_DIR . '/css/ComplexTableField_popup.css');
     Requirements::css(CMS_DIR . '/css/typography.css');
     Requirements::css(CMS_DIR . '/css/cms_right.css');
     Requirements::javascript(THIRDPARTY_DIR . "/prototype.js");
     Requirements::javascript(THIRDPARTY_DIR . "/behaviour.js");
     Requirements::javascript(THIRDPARTY_DIR . "/prototype_improvements.js");
     Requirements::javascript(THIRDPARTY_DIR . "/scriptaculous/scriptaculous.js");
     Requirements::javascript(THIRDPARTY_DIR . "/scriptaculous/controls.js");
     Requirements::javascript(THIRDPARTY_DIR . "/layout_helpers.js");
     Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
     Requirements::javascript(SAPPHIRE_DIR . "/javascript/ComplexTableField_popup.js");
     if ($this->dataObject->hasMethod('getRequirementsForPopup')) {
         $this->dataObject->getRequirementsForPopup();
     }
     return $ret;
 }
 /**
  * Apply the transformation before rendering the form HTML output.
  *
  * @return mixed
  */
 public function forTemplate()
 {
     $this->performInuitTransformation();
     return parent::forTemplate();
 }
 /**
  * @return string
  */
 public function doDelete()
 {
     if ($this->currentRecord->canDelete()) {
         $this->currentRecord->delete();
         $form = new Form($this, 'EditForm', new FieldSet(new LiteralField('RecordDeleted', '<p>' . _t('AdvancedWorkflowAdmin.RECORDDELETED', 'This record has been deleted.') . '</p>')), new FieldSet());
         return $form->forTemplate();
     } else {
         return $this->redirectBack();
     }
 }
 public function Results($searchCriteria)
 {
     switch ($searchCriteria['State']) {
         case 'approved':
             $moderationState = "approved";
             $title = "Approved";
             $commands = array('unapprove' => 'Unapprove', 'isspam' => 'Is Spam');
             break;
         case 'unapproved':
             $moderationState = "unapproved";
             $title = "Waiting Moderation";
             $commands = array('approve' => 'Approve', 'isspam' => 'Is Spam');
             break;
         default:
             $moderationState = "spam";
             $title = "Spam";
             $commands = array('approve' => 'Approve', 'isham' => 'Not Spam');
     }
     $commands['delete'] = 'Delete';
     if (($class = $this->getModelClass()) == 'All') {
         $ds = new DataObjectSet();
         foreach ($this->parentController->getManagedModels() as $class) {
             if ($class != 'All') {
                 $ds->merge(singleton($class)->getModeratedItems($moderationState, '', 'Created'));
             }
         }
     } else {
         ModeratableState::push_state($moderationState);
         $ds = DataObject::get($class, "{$this->getSearchQuery($searchCriteria)->getFilter()}", 'Created', null, $searchCriteria['Page'] * self::$page_length . ',' . self::$page_length);
         ModeratableState::pop_state();
     }
     if (!$ds) {
         return '<p>No Results</p>';
     }
     $blocks = array();
     $paging = array();
     $fields = new FieldSet();
     foreach ($searchCriteria as $k => $v) {
         if ($k != 'SecurityID') {
             $fields->push(new HiddenField($k, $k, $v));
         }
     }
     $form = new Form($this, 'SearchForm', $fields, new FieldSet());
     $form->setHTMLID('Form_CurrentSearchForm');
     $blocks[] = $form->forTemplate();
     if ($ds) {
         foreach ($ds as $do) {
             $links = array();
             foreach ($commands as $command => $text) {
                 $links[] = "<input class='action ajaxaction' type='button' value='{$text}' action='{$this->parentController->Link("{$do->ClassName}/{$do->ID}/{$moderationState}/{$command}")}' />";
             }
             $templates = array();
             foreach (array_reverse(ClassInfo::ancestry($do->ClassName)) as $class) {
                 if ($class == 'DataObject') {
                     break;
                 }
                 $templates[] = $class . 'Moderation';
             }
             $data = new ArrayData(array('ID' => $do->ID, 'ModerationLinks' => implode('', $links), 'Preview' => $do->renderWith($templates)));
             $blocks[] = $data->renderWith('ModerationPreview');
         }
     }
     if ($ds->MoreThanOnePage()) {
         // Build search info
         $paging[] = '<div>Viewing Page ' . $ds->CurrentPage() . ' of ' . $ds->TotalPages() . '</div>';
         if ($ds->NotFirstPage()) {
             $paging[] = "<input class='action pageaction' type='button' value='Prev' action='prev' />";
         }
         if ($ds->NotLastPage()) {
             $paging[] = "<input class='action pageaction' type='button' value='Next' action='next' />";
         }
     }
     $data = new ArrayData(array('State' => ucwords($searchCriteria['State']), 'Class' => $this->getModelClass(), 'Pagination' => implode("\n", $paging), 'Moderation' => implode("\n", $blocks)));
     return $data->renderWith('Moderation');
 }