/**
  * @return Form
  */
 function getEditForm($id = null, $fields = null)
 {
     $siteConfig = SiteConfig::current_site_config();
     $fields = $siteConfig->getCMSFields();
     $actions = $siteConfig->getCMSActions();
     $form = new Form($this, 'EditForm', $fields, $actions);
     $form->addExtraClass('root-form');
     $form->addExtraClass('cms-edit-form cms-panel-padded center');
     // don't add data-pjax-fragment=CurrentForm, its added in the content template instead
     if ($form->Fields()->hasTabset()) {
         $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
     }
     $form->setHTMLID('Form_EditForm');
     $form->loadDataFrom($siteConfig);
     $form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
     // Use <button> to allow full jQuery UI styling
     $actions = $actions->dataFields();
     if ($actions) {
         foreach ($actions as $action) {
             $action->setUseButtonTag(true);
         }
     }
     $this->extend('updateEditForm', $form);
     return $form;
 }
 public function GenerateCouponsForm()
 {
     $fields = Object::create('OrderCoupon')->getCMSFields();
     $fields->removeByName('Code');
     $fields->removeByName('GiftVoucherID');
     $fields->removeByName('SaveNote');
     $fields->addFieldsToTab("Root.Main", array(NumericField::create('Number', 'Number of Coupons'), FieldGroup::create("Code", TextField::create("Prefix", "Code Prefix")->setMaxLength(5), DropdownField::create("Length", "Code Characters Length", array_combine(range(5, 20), range(5, 20)), OrderCoupon::config()->generated_code_length)->setDescription("This is in addition to the length of the prefix."))), "Title");
     $actions = new FieldList(new FormAction('generate', 'Generate'));
     $validator = new RequiredFields(array('Title', 'Number', 'Type'));
     $form = new Form($this, "GenerateCouponsForm", $fields, $actions, $validator);
     $form->addExtraClass("cms-edit-form cms-panel-padded center ui-tabs-panel ui-widget-content ui-corner-bottom");
     $form->setAttribute('data-pjax-fragment', 'CurrentForm');
     $form->setHTMLID('Form_EditForm');
     $form->loadDataFrom(array('Number' => 1, 'Active' => 1, 'ForCart' => 1, 'UseLimit' => 1));
     return $form;
 }
		/**
	 * @return Form
	 */
	function getEditForm($id = null, $fields = null) {
		$siteConfig = SiteConfig::current_site_config();
		$fields = $siteConfig->getCMSFields();

		$actions = $siteConfig->getCMSActions();
		$form = new Form($this, 'EditForm', $fields, $actions);
		$form->addExtraClass('root-form');
		$form->addExtraClass('cms-edit-form');
		// TODO Can't merge $FormAttributes in template at the moment
		$form->addExtraClass('cms-content center ss-tabset');
		if($form->Fields()->hasTabset()) $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
		$form->setHTMLID('Form_EditForm');
		$form->loadDataFrom($siteConfig);
		$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));

		// Use <button> to allow full jQuery UI styling
		$actions = $actions->dataFields();
		if($actions) foreach($actions as $action) $action->setUseButtonTag(true);

		$this->extend('updateEditForm', $form);

		return $form;
	}
 /**
  *                                                                                     
  * Overload the ImportForm method of the ModelAdmin class.                             
  *                                                                                     
  * Used to remove the "Clear Database" checkbox from the import form.                  
  * This allows the functionality to be hardcoded in the MenuItemCsvBulkLoader class.   
  * See the overloaded "load" method of the MenuItemCsvBulkLoader class, where          
  * "deleteExistingRecords" is set to true.                                             
  *                                                                                     
  * @return object Form                                                                 
  */
 public function ImportForm()
 {
     $modelName = $this->modelClass;
     // check if a import form should be generated
     if (!$this->showImportForm() || is_array($this->showImportForm()) && !in_array($modelName, $this->showImportForm())) {
         return false;
     }
     $importers = $this->parentController->getModelImporters();
     if (!$importers || !isset($importers[$modelName])) {
         return false;
     }
     if (!singleton($modelName)->canCreate(Member::currentUser())) {
         return false;
     }
     $fields = new FieldSet(new HiddenField('ClassName', _t('ModelAdmin.CLASSTYPE'), $modelName), new FileField('_CsvFile', false));
     // get HTML specification for each import (column names etc.)
     $importerClass = $importers[$modelName];
     $importer = new $importerClass($modelName);
     $spec = $importer->getImportSpec();
     $specFields = new DataObjectSet();
     foreach ($spec['fields'] as $name => $desc) {
         $specFields->push(new ArrayData(array('Name' => $name, 'Description' => $desc)));
     }
     $specRelations = new DataObjectSet();
     foreach ($spec['relations'] as $name => $desc) {
         $specRelations->push(new ArrayData(array('Name' => $name, 'Description' => $desc)));
     }
     $specHTML = $this->customise(array('ModelName' => Convert::raw2att($modelName), 'Fields' => $specFields, 'Relations' => $specRelations))->renderWith('ModelAdmin_ImportSpec');
     //$fields->push(new LiteralField("SpecFor{$modelName}", $specHTML));
     //$fields->push(new CheckboxField('EmptyBeforeImport', 'Clear Database before import', false));
     $actions = new FieldSet(new FormAction('import', _t('ModelAdmin.IMPORT', 'Import from CSV')));
     $validator = new RequiredFields();
     $validator->setJavascriptValidationHandler('none');
     $form = new Form($this, "ImportForm", $fields, $actions, $validator);
     $form->setHTMLID("Form_ImportForm_" . $this->modelClass);
     return $form;
 }
 /**
  * @return Form
  */
 function RootForm()
 {
     $siteConfig = SiteConfig::current_site_config();
     $fields = $siteConfig->getCMSFields();
     if (Object::has_extension('SiteConfig', "Translatable")) {
         $fields->push(new HiddenField('Locale', '', $siteConfig->Locale));
     }
     $form = new Form($this, 'RootForm', $fields, $siteConfig->getCMSActions());
     $form->setHTMLID('Form_EditForm');
     $form->loadDataFrom($siteConfig);
     $this->extend('updateEditForm', $form);
     return $form;
 }
 /**
  * Builds a Form that mirrors the parent editForm, but with an extra field to collect the ChangeSet ID
  *
  * @param DataObject $object The object we're going to be adding to whichever ChangeSet is chosen
  * @return Form
  */
 public function Form($object)
 {
     $inChangeSets = array_unique(ChangeSetItem::get_for_object($object)->column('ChangeSetID'));
     $changeSets = $this->getAvailableChangeSets()->map();
     $campaignDropdown = DropdownField::create('Campaign', '', $changeSets);
     $campaignDropdown->setEmptyString(_t('Campaigns.AddToCampaign', 'Select a Campaign'));
     $campaignDropdown->addExtraClass('noborder');
     $campaignDropdown->setDisabledItems($inChangeSets);
     $fields = new FieldList([$campaignDropdown, HiddenField::create('ID', null, $this->data['ID']), HiddenField::create('ClassName', null, $this->data['ClassName'])]);
     $form = new Form($this->editForm->getController(), $this->editForm->getName(), new FieldList($header = new CompositeField(new LiteralField('Heading', sprintf('<h3>%s</h3>', _t('Campaigns.AddToCampaign', 'Add To Campaign')))), $content = new CompositeField($fields)), new FieldList($action = AddToCampaignHandler_FormAction::create()));
     $header->addExtraClass('add-to-campaign__header');
     $content->addExtraClass('add-to-campaign__content');
     $action->addExtraClass('add-to-campaign__action');
     $form->setHTMLID('Form_EditForm_AddToCampaign');
     $form->unsetValidator();
     $form->loadDataFrom($this->data);
     $form->addExtraClass('add-to-campaign__form');
     return $form;
 }
    function getEPayForm()
    {
        Requirements::javascript("http://www.epay.dk/js/standardwindow.js");
        Requirements::javascript(THIRDPARTY_DIR . "/jquery/jquery.js");
        $customscript = <<<JS
\t\t\tjQuery(document).ready(function(\$) {\t\t\t\t
\t\t\t\t\$("form#ePay").submit(function(){
\t\t\t\t\topen_ePay_window();
\t\t\t\t\treturn false;
\t\t\t\t});
\t\t\t\t
\t\t\t});\t
JS;
        if (Director::isLive()) {
            $customscript .= <<<JS
\t\t\t\tjQuery(document).ready(function(\$) {
\t\t\t\t\topen_ePay_window(); //enable for auto-submit
\t\t\t\t\t\$("form#ePay").hide();
\t\t\t\t});\t
JS;
        }
        Requirements::customScript($customscript, 'epayinit');
        $controller = new EpaydkPayment_Controller();
        //http://tech.epay.dk/ePay-Payment-Window-technical-documentation_9.html
        $fields = new FieldSet(new HiddenField('merchantnumber', 'Merchant Number', self::$merchant_number), new HiddenField('orderid', 'Order ID', $this->ID), new HiddenField('currency', 'Currency', self::$supported_currencies[$this->Amount->Currency]['code']), new HiddenField('amount', 'Amount', $this->Amount->Amount * 100), new HiddenField('language', 'Language', self::$language), new HiddenField('accepturl', 'Accept URL', Director::absoluteBaseURL() . $controller->Link('accept')), new HiddenField('declineurl', 'Decline URL', Director::absoluteBaseURL() . $controller->Link('decline')), new HiddenField('callbackurl', 'Callback URL', Director::absoluteBaseURL() . $controller->Link('callback')), new HiddenField('instantcallback', 'Instant Callback', 1), new HiddenField('instantcapture', 'Instant Capture', 1), new HiddenField('windowstate', 'Window State', 2), new HiddenField('ownreceipt', 'Own Receipt', 1));
        //custom configs
        if (self::$md5key) {
            $md5data = $this->generateMD5();
            $fields->push(new HiddenField('md5key', 'MD5 Key', $md5data));
        }
        if (self::$limit_card_types) {
            $fields->push(new HiddenField('cardtype', 'Card Type', self::$limit_card_types));
        }
        if (self::$add_fee) {
            $fields->push(new HiddenField('addfee', 'Add Fee', 1));
        }
        if (self::$auth_sms) {
            $fields->push(new HiddenField('authsms', 'Auth SMS', self::$auth_sms));
        }
        if (self::$auth_mail) {
            $fields->push(new HiddenField('authmail', 'Auth Mail', self::$auth_mail));
        }
        if (self::$google_tracker) {
            $fields->push(new HiddenField('googletracker', 'Google Tracker', self::$google_tracker));
        }
        if (self::$use3d) {
            $fields->push(new HiddenField('use3D', 'Use 3D', self::$use3d));
        }
        $actions = new FieldSet($openwindow = new FormAction('openwindow', _t('EpaydkPayment.OPENPAYMENTWINDOW', 'Open the ePay Payment Window')));
        $form = new Form($controller, 'ePay', $fields, $actions);
        $form->setHTMLID('ePay');
        $form->setFormAction(self::$submit_url);
        $form->unsetValidator();
        $form->disableSecurityToken();
        return $form;
    }
Example #8
0
 /**
  * @return Form
  */
 function RootForm()
 {
     $siteConfig = SiteConfig::current_site_config();
     $fields = $siteConfig->getCMSFields();
     $form = new Form($this, 'RootForm', $fields, $siteConfig->getCMSActions());
     $form->addExtraClass('root-form');
     $form->addExtraClass('cms-edit-form');
     // TODO Can't merge $FormAttributes in template at the moment
     $form->addExtraClass('cms-content center ss-tabset');
     if ($form->Fields()->hasTabset()) {
         $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
     }
     $form->setHTMLID('Form_EditForm');
     $form->loadDataFrom($siteConfig);
     $form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
     $this->extend('updateEditForm', $form);
     return $form;
 }
Example #9
0
 /**
  * Get a search form for a single {@link DataObject} subclass.
  * 
  * @return Form
  */
 public function SearchForm()
 {
     $context = singleton($this->modelClass)->getDefaultSearchContext();
     $fields = $context->getSearchFields();
     $columnSelectionField = $this->ColumnSelectionField();
     $fields->push($columnSelectionField);
     $form = new Form($this, "SearchForm", $fields, new FieldSet(new FormAction('search', _t('MemberTableField.SEARCH', 'Search')), $clearAction = new ResetFormAction('clearsearch', _t('ModelAdmin.CLEAR_SEARCH', 'Clear Search'))));
     //$form->setFormAction(Controller::join_links($this->Link(), "search"));
     $form->setFormMethod('get');
     $form->setHTMLID("Form_SearchForm_" . $this->modelClass);
     $clearAction->useButtonTag = true;
     $clearAction->addExtraClass('minorAction');
     return $form;
 }
 public function getNewsletterEditForm($myId)
 {
     $email = DataObject::get_by_id("Newsletter", $myId);
     if ($email) {
         $fields = $email->getCMSFields($this);
         $fields->push($idField = new HiddenField("ID"));
         $idField->setValue($myId);
         $fields->push($ParentidField = new HiddenField("ParentID"));
         $ParentidField->setValue($email->ParentID);
         $fields->push($typeField = new HiddenField("Type"));
         $typeField->setValue('Newsletter');
         //$fields->push(new HiddenField("executeForm", "", "EditForm") );
         $actions = new FieldSet();
         if ($email->SentDate) {
             $actions->push(new FormAction('send', _t('NewsletterAdmin.RESEND', 'Resend')));
         } else {
             $actions->push(new FormAction('send', _t('NewsletterAdmin.SEND', 'Send...')));
         }
         $actions->push(new FormAction('save', _t('NewsletterAdmin.SAVE', 'Save')));
         $form = new Form($this, "NewsletterEditForm", $fields, $actions);
         $form->loadDataFrom($email);
         // This saves us from having to change all the JS in response to renaming this form to NewsletterEditForm
         $form->setHTMLID('Form_EditForm');
         if ($email->Status != 'Draft') {
             $readonlyFields = $form->Fields()->makeReadonly();
             $form->setFields($readonlyFields);
         }
         // user_error( $form->FormAction(), E_USER_ERROR );
         return $form;
     } else {
         user_error('Unknown Email ID: ' . $myId, E_USER_ERROR);
     }
 }
 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');
 }
 public function getNewsletterEditForm($myId)
 {
     $email = DataObject::get_by_id("Newsletter", $myId);
     if ($email) {
         $fields = $email->getCMSFields($this);
         $actions = $email->getCMSActions();
         $fields->push($idField = new HiddenField("ID"));
         $idField->setValue($myId);
         $fields->push($ParentidField = new HiddenField("ParentID"));
         $ParentidField->setValue($email->ParentID);
         $fields->push($typeField = new HiddenField("Type"));
         $typeField->setValue('Newsletter');
         $form = new Form($this, "NewsletterEditForm", $fields, $actions);
         $form->loadDataFrom($email);
         // This saves us from having to change all the JS in response to renaming this form to NewsletterEditForm
         $form->setHTMLID('Form_EditForm');
         if ($email->Status != 'Draft') {
             $readonlyFields = $form->Fields()->makeReadonly();
             $form->setFields($readonlyFields);
         }
         $this->extend('updateEditForm', $form);
         return $form;
     } else {
         user_error('Unknown Email ID: ' . $myId, E_USER_ERROR);
     }
 }