/**
  * simplified method
  * @return HTML
  **/
 function dataObjectSorterPopupLink($filterField = '', $filterValue = '', $alternativeTitle = '')
 {
     if ($alternativeTitle) {
         $linkText = $alternativeTitle;
     } else {
         $linkText = "Sort " . $this->owner->plural_name();
     }
     return DataObjectSorterController::popup_link($this->owner->ClassName, $filterField, $filterValue, $linkText);
 }
 function getCMSFields()
 {
     $fields = parent::getCMSFields();
     //TODO: make this a really fast editing interface. Table list field??
     //$fields->removeFieldFromTab('Root.Values','Values');
     if (class_exists("DataObjectSorterController")) {
         $sortLink = DataObjectSorterController::popup_link($className = "ProductAttributeType", $filterField = "", $filterValue = "", $linkText = "Sort Types");
         $fields->addFieldToTab("Root.Sort", new LiteralField("SortTypes", $sortLink));
     }
     return $fields;
 }
 function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->addFieldToTab("Root.Gallery", new TreeDropdownField($name = "AutomaticallyIncludedFolderID", $title = "Automatically Included Folder (save page to update) - go to Files and Images section to create folder and upload images.", $sourceObjectName = "Folder"));
     $gridField = new GridField('images', 'Linked images', $this->ImageGalleryEntries(), GridFieldConfig_RelationEditor::create());
     $fields->addFieldToTab("Root.Gallery", $gridField);
     if (class_exists("DataObjectSorterController")) {
         $fields->addFieldToTab("Root.Gallery", new LiteralField("ImageGalleryEntrySorter", DataObjectSorterController::popup_link("ImageGalleryEntry", $filterField = "ParentID", $filterValue = $this->ID, $linkText = "Sort " . $this->Config()->get("ImageGalleryEntry", "plural_name"), $titleField = "FullTitle")));
     } else {
         $fields->addFieldToTab("Root.Gallery", new NumericField($name = "Sort", "Sort index number (the lower the number, the earlier it shows up"));
     }
     return $fields;
 }
 function getCMSFields()
 {
     $fields = parent::getCMSFields();
     //TODO: make this a really fast editing interface. Table list field??
     //$fields->removeFieldFromTab('Root.Values','Values');
     if (class_exists("DataObjectSorterController")) {
         $sortLink = DataObjectSorterController::popup_link($className = "ProductAttributeValue", $filterField = "TypeID", $filterValue = $this->TypeID, $linkText = "Sort Values");
         $fields->addFieldToTab("Root.Sort", new LiteralField("SortValues", $sortLink));
     }
     // TO DO: the code below does not work...
     //$fields->removeFieldFromTab("Root.Product Variation", "ProductVariation");
     //$fields->removeFieldFromTab("Root", "Product Variation");
     $table = $fields->fieldByName("ProductVariation");
     if ($table) {
         $table->setPermissions("edit", "view");
     }
     return $fields;
 }
 function ValueSorterLink()
 {
     if (class_exists("DataObjectSorterController")) {
         return DataObjectSorterController::popup_link($className = "ProductAttributeValue", $filterField = "TypeChangeToId", $filterValue = "ID", $linkText = "Sort Values");
     }
 }
 function SortProductsLink()
 {
     if (class_exists("DataObjectSorterController")) {
         return DataObjectSorterController::popup_link($className = "MerchantProduct", $filterField = "ParentID", $filterValue = $this->ID, $linkText = _t("MerchantProduct.SORT_PRODUCT_LIST", "Producten sorteren"), $titleField = "Title");
     }
 }
 public function updateCMSFields(FieldList $fields)
 {
     if ($this->classHasAdvertisements($this->owner->ClassName)) {
         $tabName = $this->MyTabName();
         //advertisements shown...
         $where = '1 = 1';
         if ($this->owner->AdvertisementsFolderID) {
             $images = Image::get()->filter("ParentID", $this->owner->AdvertisementsFolderID);
             if ($images->count()) {
                 $where = "\"AdvertisementImageID\" IN (" . implode(",", $images->column("ID")) . ")";
             } else {
                 $where = " 1 = 2";
             }
         }
         //$advertisementsCount = DB::query("SELECT COUNT(ID) FROM \"Advertisement\" $whereDB ;")->value();
         $advertisements = $this->owner->Advertisements()->where($where);
         $txt = sprintf(_t("AdvertisementDecorator.ACTUAL", 'Current %1$s Shown'), Config::inst()->get("Advertisement", "plural_name"));
         $fields->addFieldToTab($tabName, $this->MyHeaderField($txt));
         $txt = sprintf(_t("AdvertisementDecorator.SELECT", 'Select %1$s to show ... '), Config::inst()->get("Advertisement", "plural_name"));
         $advertisementsGridField = new GridField('Advertisements', $txt, $this->owner->Advertisements(), GridFieldConfig_RelationEditor::create());
         $fields->addFieldToTab($tabName, $advertisementsGridField);
         if (Config::inst()->get("Advertisement", "resize_images") == 'no') {
             $totalSize = 0;
             foreach ($this->owner->Advertisements() as $advertisement) {
                 $totalSize += $advertisement->AdvertisementImage()->getAbsoluteSize();
             }
             $seconds = round(($totalSize + 1) / 524288);
             $fields->addFieldToTab($tabName, new LiteralField("TotalSize", '<p><em>Total download size: ' . File::format_size($totalSize) . ', good reception 3G network download time less than ~' . ($seconds + 1) . ' seconds.</em></p>'));
         }
         if (class_exists("DataObjectSorterController")) {
             $shownAdvertisements = $this->owner->getManyManyComponents('Advertisements');
             if ($shownAdvertisements) {
                 $array = $shownAdvertisements->column("ID");
                 $idString = implode(",", $array);
                 $link = DataObjectSorterController::popup_link("Advertisement", $filterField = "ID", $filterValue = $idString, $linkText = "sort " . Config::inst()->get("Advertisement", "plural_name"), $titleField = "FullTitle");
                 $fields->addFieldToTab($tabName, new LiteralField("AdvertisementsSorter", $link));
             }
         }
         if ($advertisements->count()) {
         } else {
             $txt = sprintf(_t("AdvertisementDecorator.CREATE", '<p>Please <a href="admin/%1$s/">create %2$s</a> on the <a href="admin/%1$s/">%3$s tab</a> first, or see below on how to create %2$s from a folder.</p>'), Config::inst()->get("AdvertisementAdmin", "url_segment"), Config::inst()->get("Advertisement", "plural_name"), Config::inst()->get("AdvertisementAdmin", "menu_title"));
             $fields->addFieldToTab($tabName, new LiteralField("AdvertisementsHowToCreate", $txt));
         }
         if ($parent = $this->advertisementParent()) {
             $txt = sprintf(_t("AdvertisementDecorator.ORUSE", 'OR  ... use %1$s from  <i>%2$s</i>.'), Config::inst()->get("Advertisement", "plural_name"), $parent->Title);
             $fields->addFieldToTab($tabName, new CheckboxField("UseParentAdvertisements", $txt));
         }
         //create new advertisements
         $txt = sprintf(_t("AdvertisementDecorator.CREATE", 'Create new %1$s'), Config::inst()->get("Advertisement", "plural_name"));
         $fields->addFieldToTab($tabName, $this->MyHeaderField($txt));
         $txt = sprintf(_t("AdvertisementDecorator.CREATENEWFROMFOLDER_EXPLANATION", 'Create New %1$s from images in the folder selected - each image in the folder will be used to create a %3$s. %2$s'), Config::inst()->get("Advertisement", "plural_name"), Advertisement::recommended_image_size_statement(), Config::inst()->get("Advertisement", "singular_name"));
         if (Folder::get()->count()) {
             $fields->addFieldToTab($tabName, $treeDropdownField = new TreeDropdownField('AdvertisementsFolderID', _t("AdvertisementDecorator.CREATENEWFROMFOLDER", "Create from folder"), 'Folder'));
             $treeDropdownField->setRightTitle($txt);
         }
         $styles = AdvertisementStyle::get();
         if ($styles->count()) {
             $fields->addFieldToTab($tabName, $this->MyHeaderField("Style"));
             $list = $styles->map("ID", "Title", $emptyString = _t("AdvertisementDecorator.SELECTSTYLE", "--select style--"), $sortByTitle = true);
             $fields->addFieldToTab($tabName, $selectStyleField = new DropdownField("AdvertisementStyleID", _t("AdvertisementDecorator.STYLECREATED", "Select style"), $list));
             $selectStyleField->setRightTitle(_t("AdvertisementDecorator.STYLECREATED_EXPLANATION", "Styles are created by your developer"));
         }
         $txt = sprintf(_t("AdvertisementDecorator.EDIT", 'Edit %1$s'), Config::inst()->get("Advertisement", "plural_name"));
         $fields->addFieldToTab($tabName, $this->MyHeaderField($txt));
         $txt = sprintf(_t("AdvertisementDecorator.PLEASEMANAGEEXISTING", '<p>Please manage existing %1$s on the <a href="admin/%2$s/">%3$s tab</a>.</p>'), Config::inst()->get("Advertisement", "plural_name"), Config::inst()->get("AdvertisementAdmin", "url_segment"), Config::inst()->get("AdvertisementAdmin", "menu_title"));
         $fields->addFieldToTab($tabName, new LiteralField("ManageAdvertisements", $txt));
         $txt = sprintf(_t("AdvertisementDecorator.DELETE", 'Delete %1$s'), Config::inst()->get("Advertisement", "plural_name"));
         $fields->addFieldToTab($tabName, $this->MyHeaderField($txt));
         $page = SiteTree::get()->byID($this->owner->ID);
         $txtRemove = sprintf(_t("AdvertisementDecorator.REMOVE", 'Remove all %1$s from this page (%1$s will not be deleted but are not longer associated with this page)'), Config::inst()->get("Advertisement", "plural_name"));
         $txtConfirmRemove = sprintf(_t("AdvertisementDecorator.CONFIRMREMOVE", 'Are you sure you want to remove all %1$s from this page?'), Config::inst()->get("Advertisement", "plural_name"));
         $removeallLink = 'advertisements/removealladvertisements/' . $this->owner->ID . '/';
         $jquery = 'if(confirm(\'' . $txtConfirmRemove . '\')) {jQuery(\'#removealladvertisements\').load(\'' . $removeallLink . '\');} return false;';
         $fields->addFieldToTab($tabName, new LiteralField("removealladvertisements", '<p class="message warning"><a href="' . $removeallLink . '" onclick="' . $jquery . '"  id="removealladvertisements"  class="ss-ui-button">' . $txtRemove . '</a></p>'));
         $txtDelete = sprintf(_t("AdvertisementDecorator.DELETE", 'Delete all %1$s from this website (but not the images associated with them)'), Config::inst()->get("Advertisement", "plural_name"));
         $txtConfirmDelete = sprintf(_t("AdvertisementDecorator.CONFIRMDELETE", 'Are you sure you want to delete all %1$s - there is no UNDO?'), Config::inst()->get("Advertisement", "plural_name"));
         $deleteallLink = 'advertisements/deletealladvertisements/' . $this->owner->ID . '/';
         $jquery = 'if(confirm(\'' . $txtConfirmDelete . '\')) {jQuery(\'#deletealladvertisements\').load(\'' . $deleteallLink . '\');} return false;';
         $fields->addFieldToTab($tabName, new LiteralField("deletealladvertisements", '<p class="message bad"><a href="' . $deleteallLink . '" onclick="' . $jquery . '"  id="deletealladvertisements" class="ss-ui-button">' . $txtDelete . '</a></p>'));
     }
     return $fields;
 }