public function __construct($parent, $name)
 {
     parent::__construct($parent, $name);
     // getLanguages
     $langs = $this->presenter->langManagerService->getLangs();
     $langForms = array();
     $parentData = array(0 => 'Nejvyšší úroveň');
     $identifier = $this->presenter->getParam('identifier');
     $treeNodeId = $this->presenter->getParam('id');
     //        $this->addHidden('tree_node_id', $this->presenter->getParam('id'));
     //        $this->addHidden('identifier', $this->presenter->getParam('identifier'));
     // identifier and treeNodeId serve as clues to find all parent attribs
     // current ext_tree_node_id (is any) must be excluded
     //dump();
     $structuredParamsParentSelectData = $this->presenter->extModel->getStructuredParamsParentSelectData($identifier, $treeNodeId, $this->presenter->langManagerService->getDefaultLanguage(), $this->presenter->getParam('ext_tree_node_id'));
     //dump($structuredParamsParentSelectData);
     $this->addSelect('parent', 'Rodičovský parametr', $parentData + $structuredParamsParentSelectData);
     $this->addText('x_coord', 'X');
     $this->addText('y_coord', 'Y');
     $this->addTextArea('image', 'Obrázek')->getControlPrototype()->class = 'wysiwyg';
     //dump($langs);
     // language containers
     foreach ($langs as $langCode => $language) {
         // !! create language section
         $langForms[$langCode] = $this->addContainer($langCode);
         $langForms[$langCode]->addText('param_name', 'Jméno parametru');
         $langForms[$langCode]->addTextArea('text', 'Text')->getControlPrototype()->class = 'wysiwyg';
     }
     //dump($langForms);
     $labelId = $this->presenter->getParam('labelId');
     $this->addHidden('label_id', $this->presenter->getParam('labelId'));
     $this->addHidden('tree_node_id', $this->presenter->getParam('id'));
     $this->addHidden('identifier', $this->presenter->getParam('identifier'));
     switch ($this->getPresenter()->getAction()) {
         case 'addStructuredParam':
             $this->addSubmit('send', 'Vytvořit');
             $this->onSuccess[] = array($this, 'addformSubmited');
             break;
         case 'editStructuredParam':
             // edit
             $this->addSubmit('send', 'Uložit');
             $extTreeNodeId = $this->presenter->getParam('ext_tree_node_id');
             $this->addHidden('ext_tree_node_id', $extTreeNodeId);
             $defaults = $this->presenter->extModel->getParam($extTreeNodeId, $this->presenter->tags);
             //                dump($extTreeNodeId);
             //                dump($defaults);
             //                die();
             foreach ($langs as $langCode => $lang) {
                 if (isset($defaults[$langCode])) {
                     if (isset($defaults[$langCode]['param_value'])) {
                         //                            dump((array)\Bubo\Utils\MultiValues::unserialize($defaults[$langCode]['param_value']));
                         //                            die();
                         $defaults['parent'] = isset($defaults[$langCode]['parent']) ? $defaults[$langCode]['parent'] : NULL;
                         $defaults[$langCode] = (array) $defaults[$langCode] + (array) \Bubo\Utils\MultiValues::unserialize($defaults[$langCode]['param_value']);
                         $defaults['x_coord'] = isset($defaults[$langCode]['x_coord']) ? $defaults[$langCode]['x_coord'] : '';
                         $defaults['y_coord'] = isset($defaults[$langCode]['y_coord']) ? $defaults[$langCode]['y_coord'] : '';
                         $defaults['image'] = isset($defaults[$langCode]['image']) ? $defaults[$langCode]['image'] : '';
                     }
                 }
             }
             //                dump($defaults);
             //                die();
             $this->onSuccess[] = array($this, 'editFormSubmited');
             $this->setDefaults((array) $defaults);
             break;
     }
 }
Example #2
0
 public function __construct($parent, $name)
 {
     parent::__construct($parent, $name);
     $treeNodeId = $this->presenter->getParam('id');
     $labelId = $this->presenter->getParam('labelId');
     $entity = $this->presenter->getParam('entity');
     if ($entity === NULL) {
         // determine entity by $treeNodeId
         if ($treeNodeId === NULL) {
             throw new \Nette\InvalidArgumentException("Unable to determine entity");
         }
         $entity = $this->presenter->pageModel->getEntity($treeNodeId);
     }
     // load page configuration
     $entityConfig = $this->presenter->configLoaderService->loadEntityConfig($entity);
     $this->properties = $this->presenter->extModel->filterEntityProperties($entityConfig['properties'], $labelId);
     $this->createUrl = TRUE;
     if (isset($entityConfig['entityMeta']) && isset($entityConfig['entityMeta']['createUrl'])) {
         if (!$entityConfig['entityMeta']['createUrl']) {
             $this->createUrl = FALSE;
         }
     }
     $labelProperties = array();
     $label = NULL;
     // for proper form generation...$labelId must be known
     if (!empty($labelId)) {
         // load all label extensions
         $allExtensions = $this->presenter->configLoaderService->loadLabelExtentsionProperties();
         $labelProperties = $this->presenter->pageManagerService->intersectLabelProperties($labelId, $allExtensions);
         $this->properties = array_merge($this->properties, $labelProperties);
         // sort properties
         $extSortOrder = $this->presenter->extModel->loadExtSorting($labelId);
         if ($extSortOrder) {
             $extSorting = NULL;
             if ($extSorting = \Bubo\Utils\MultiValues::unserialize($extSortOrder)) {
                 uksort($this->properties, function ($a, $b) use($extSorting) {
                     $aPos = array_search(str_replace('_', '*', $a), $extSorting);
                     $bPos = array_search(str_replace('_', '*', $b), $extSorting);
                     if ($aPos !== FALSE && $bPos !== FALSE) {
                         return $aPos - $bPos;
                     } else {
                         if ($aPos === FALSE) {
                             return -1;
                         } else {
                             return 1;
                         }
                     }
                 });
             }
         }
         $label = $this->presenter->pageManagerService->getLabel($labelId);
     }
     // getLanguages
     $langs = $originalLangs = $this->presenter->langManagerService->getLangs();
     $alienLangs = array();
     $referencingPages = NULL;
     if ($treeNodeId !== NULL) {
         //$defaults = $this->presenter->pageManagerService->getDefaults($treeNodeId, $this->presenter->getParam('waiting'));
         $referencingPages = $this->presenter->pageModel->getReferencingPages($treeNodeId);
         $alienLangs = $this->presenter->langManagerService->getAlienLangs($referencingPages, $langs);
         $langs = $langs + $alienLangs;
     }
     $pageNameListeners = array('title', 'link_title', 'menu_title', 'page_title', 'url_name');
     if ($this->presenter->preselectedParent !== NULL) {
         if (is_array($this->presenter->preselectedParent)) {
             $this->addSelect('parent', "Parent", $this->presenter->preselectedParent)->setPrompt(':: Vyberte předka ::')->setRequired('Musíte vybrat předka');
             $this['parent']->getControlPrototype()->style = 'font-family:monospace;float:right;z-index:250;font-size:12px;';
         } else {
             $this->addHidden('parent', $this->presenter->preselectedParent);
         }
     } else {
         // parent select
         //dump($entityConfig);
         $disablePagesWithNoUrl = isset($entityConfig['entityMeta']['createUrl']) ? $entityConfig['entityMeta']['createUrl'] : FALSE;
         //dump($disablePagesWithNoUrl);
         $st = new \BuboApp\AdminModule\Components\SelectTraverser($this->presenter, $treeNodeId, NULL, $disablePagesWithNoUrl);
         $selectData = $st->getSelectMenu($this->presenter['structureManager']->getLanguage());
         $this->addSelect('parent', "Parent", $selectData)->setPrompt(':: Vyberte předka ::')->setRequired('Musíte vybrat předka');
         $this['parent']->getControlPrototype()->style = 'font-family:monospace;float:right;z-index:250;font-size:12px;';
     }
     $this->addHidden('entity');
     $identity = $this->presenter->getUser()->getIdentity();
     $editorId = $identity ? $identity->id : NULL;
     $mandatoryProperties = $this->presenter->configLoaderService->loadMandatoryProperties();
     $langForms = array();
     if (!empty($this->properties)) {
         // container with checkboxes
         $publishContainer = $this->addContainer('lang_versions');
         foreach ($langs as $langCode => $language) {
             $publishContainer->addCheckbox($langCode);
         }
         // language containers
         foreach ($langs as $langCode => $language) {
             // !! create language section
             $langForms[$langCode] = $this->addContainer($langCode);
             //                dump($mandatoryProperties);
             //                die();
             // mandatory parameters (will be in all pageForms??)
             foreach ($mandatoryProperties as $key => $array) {
                 $formItem = NULL;
                 switch ($array['type']) {
                     case 'text':
                         $formItem = $langForms[$langCode]->addText($key, $array['label']);
                         break;
                     case 'textArea':
                         $formItem = $langForms[$langCode]->addTextArea($key, $array['label']);
                         break;
                 }
                 if ($formItem !== NULL) {
                     if (isset($array['class'])) {
                         $formItem->getControlPrototype()->class[] = $array['class'];
                     }
                     $formItem->getLabelPrototype()->title = '_' . $key;
                 }
                 // manage classes for name and its listeners
                 if ($key == 'name') {
                     $formItem->getControlPrototype()->class[] = '_page_name_' . $langCode;
                 } else {
                     if (in_array($key, $pageNameListeners)) {
                         $formItem->getControlPrototype()->class[] = '_page_name_listener_' . $langCode;
                     }
                 }
             }
             $langForms[$langCode]->addText('parent_url')->addConditionOn($langForms[$langCode]['name'], Form::FILLED)->addRule(~Form::EQUAL, 'Předek je duch. Pro uložení stránky v této mutaci je potřeba nejprve vytvořit předka.', '_undefin@_');
             //                dump($labelProperties);
             //                die();
             // parameters loaded from page configuration
             foreach ($this->properties as $propertyName => $property) {
                 $formItem = NULL;
                 if (isset($property['engine'])) {
                     switch ($property['engine']) {
                         case 'media':
                             switch ($property['type']) {
                                 case 'mediaFile':
                                     $formItem = $langForms[$langCode]->addMediaFile($propertyName, $property['label']);
                                     break;
                                 case 'mediaGallery':
                                     $formItem = $langForms[$langCode]->addMediaFile($propertyName, $property['label']);
                                     break;
                             }
                             break;
                         case 'label':
                             $currentLanguage = $this->presenter['structureManager']->getLanguage();
                             $st = new \BuboApp\AdminModule\Components\SelectTraverser($this->presenter);
                             $label = $this->presenter->pageManagerService->getLabelByName($property['bind']['labelName']);
                             $selectData = array();
                             if ($label !== NULL) {
                                 $labelRoots = $this->presenter->pageManagerService->getLabelRoots($label['label_id'], $currentLanguage);
                                 $myRoot = reset($labelRoots);
                                 $st->setTopLevelPage($myRoot);
                                 $st->hideRootElement();
                                 $selectData = $st->getSelectMenu($currentLanguage);
                             }
                             $formItem = $langForms[$langCode]->addSelect($propertyName, $property['label'], $selectData);
                             if (isset($property['prompt'])) {
                                 $formItem->setPrompt($property['prompt']);
                             }
                             $formItem->getControlPrototype()->style = 'font-family:monospace;font-size:12px;';
                     }
                 } else {
                     switch ($property['type']) {
                         case 'text':
                         case 'external_url':
                             $formItem = $langForms[$langCode]->addText($propertyName, $property['label']);
                             if (isset($property['class'])) {
                                 $formItem->getControlPrototype()->class = $property['class'];
                             }
                             break;
                         case 'textArea':
                             $formItem = $langForms[$langCode]->addTextArea($propertyName, $property['label']);
                             if (isset($property['class'])) {
                                 $formItem->getControlPrototype()->class = $property['class'];
                             }
                             break;
                         case 'checkbox':
                             $formItem = $langForms[$langCode]->addCheckbox($propertyName, $property['label']);
                             if (isset($property['class'])) {
                                 $formItem->getControlPrototype()->class = $property['class'];
                             }
                             break;
                         case 'select':
                             $selectData = isset($property['data']) ? $property['data'] : call_user_func_array(array($this->presenter, $property['method']), array());
                             $formItem = $langForms[$langCode]->addSelect($propertyName, $property['label'], $selectData);
                             if (isset($property['prompt'])) {
                                 $formItem->setPrompt($property['prompt']);
                             }
                             if (isset($property['required'])) {
                                 $formItem->setRequired($property['required']);
                             }
                             break;
                         case 'color':
                             $formItem = $langForms[$langCode]->addText($propertyName, $property['label']);
                             $formItem->getControlPrototype()->type = 'color';
                             break;
                     }
                 }
                 if ($formItem !== NULL) {
                     $formItem->getLabelPrototype()->title = '_' . $propertyName;
                 }
             }
         }
     }
     $this->addSubmit('send', 'Proveď');
     $this->addSubmit('cancel', 'Cancel')->setValidationScope(FALSE);
     $whatToPublish = array('none' => 'Uložit a nepublikovat nic', 'selected' => 'Uložit a publikovat vybrané', 'all' => 'Uložit a publikovat vše');
     $this->addSelect('what_to_publish', '', $whatToPublish)->addRule(array($this, 'draftNotInFuture'), 'Draft nemůže mít odloženou publikaci', $this)->addRule(array($this, 'atLeastOnePageFilled'), 'Vyplňte alespoň jednu stránku', $this)->getControlPrototype()->style = 'display: inline;';
     // load templates -> get only existing and with nice names (if possible)
     $loadTemplatesWithUrl = TRUE;
     if (isset($entityConfig['entityMeta']) && isset($entityConfig['entityMeta']['createUrl'])) {
         $loadTemplatesWithUrl = $entityConfig['entityMeta']['createUrl'];
     } else {
         throw new Nette\InvalidArgumentException("Missing parameter 'createUrl' in entity config");
     }
     $_templates = $this->presenter->projectManagerService->getListOfTemplates($loadTemplatesWithUrl);
     $templateConfig = $this->presenter->configLoaderService->loadLayoutConfig();
     $res = \Nette\Utils\Arrays::mergeTree($templateConfig['layouts'], $_templates);
     $templates = array_intersect_key($res, $_templates);
     // any entity template restriction?
     if (isset($entityConfig['templates']) && isset($entityConfig['templates']['restrict'])) {
         $templates = array_intersect_key($templates, array_flip($entityConfig['templates']['restrict']));
         if (empty($templates)) {
             throw new \Nette\InvalidStateException('Template restriction is empty.');
         }
     }
     // any entity template exclusion?
     if (isset($entityConfig['templates']) && isset($entityConfig['templates']['exclude'])) {
         $templates = array_diff_key($templates, array_flip($entityConfig['templates']['exclude']));
         if (empty($templates)) {
             throw new \Nette\InvalidStateException('Template exlusion is empty.');
         }
     }
     //        dump($templates);
     //        die();
     //
     //        dump($templates, $entityConfig);
     //        die();
     //        if (isset($_templates['headless'])) {
     //            $res = \Nette\Utils\Arrays::mergeTree($templateConfig['layouts'], $_templates['headless']);
     //            $templates['Stránky bez url'] = array_intersect_key($res, $_templates['headless']);
     //        }
     $this->addSelect('layout', 'Šablona', $templates);
     //        dump($label);
     //        die();
     if ($label && $label['lock_layout'] == 1) {
         $this['layout']->setDisabled();
         //            dump($label);
         //            die();
     }
     $this['send']->getControlPrototype()->class = "submit";
     $this['cancel']->getControlPrototype()->class = "submit";
     //$this['send']->addRule(callback($this, 'newUrlUniqueValidator'), '', $this);
     //        if (!$isEditable) {
     //            foreach ($this->getComponents() as $component) {
     //                $component->setDisabled();
     //            }
     //        }
     $this->getElementPrototype()->onsubmit('tinyMCE.triggerSave()');
     switch ($this->getPresenter()->getAction()) {
         case 'default':
             // edit
             $this->addSubmit('move_to_trash', 'Hodit do koše')->setValidationScope(FALSE);
             $this->onSuccess[] = array($this, 'editFormSubmited');
             if (!$this->isSubmitted()) {
                 //                    dump($alienLangs);
                 //                    die();
                 $defaults = $this->presenter->pageManagerService->getDefaults($treeNodeId, $this->presenter->getParam('waiting'), array_keys($alienLangs));
                 //\Nette\Diagnostics\Debugger::$maxDepth = 8;
                 //                    dump($defaults);
                 //                    die();
                 $currentDefault = reset($defaults);
                 //                    $currentDefault = current($ccurrentDefault);
                 //$allLanguages = $this->presenter->langManagerService->getLangs();
                 $defaultLanguage = $this->presenter->langManagerService->getDefaultLanguage();
                 $urls = $this->presenter->pageModel->getPagesUrls($currentDefault['parent'], array_keys($originalLangs), $defaultLanguage);
                 $alienUrls = $this->presenter->pageModel->getAlienPagesUrls($referencingPages, $alienLangs, $this->presenter->langManagerService);
                 $alienTabUrls = $this->presenter->pageModel->getAlienTabUrls($alienLangs, $alienUrls);
                 //dump($referencingPages);
                 //                    dump($referencingPages, $alienUrls);
                 //                    $this->presenter->pageModel->getAllAlienUrls($referencingPages, $alienUrls, $this->presenter->langManagerService);
                 //                    die();
                 //                    die();
                 $urls = $urls + $alienTabUrls;
                 // add urls to defauls (even to nonexisting lang sections!)
                 if (!empty($urls)) {
                     foreach ($urls as $langCode => $parentUrl) {
                         $defaults[$langCode]['parent_url'] = $urls[$langCode]['parent_url'];
                     }
                 }
                 //                    dump($currentDefault);
                 $defaults['parent'] = $currentDefault['parent'];
                 $defaults['layout'] = $currentDefault['layout'];
                 $defaults['entity'] = $entity;
                 // expand extended values
                 $identifiers = array();
                 foreach ($langs as $langCode => $langName) {
                     if (isset($defaults[$langCode]) && isset($defaults[$langCode]['time_zone'])) {
                         foreach ($defaults[$langCode]['time_zone'] as $timeZoneFlag => $timeZone) {
                             foreach ($timeZone as $status => $labels) {
                                 foreach ($labels as $labelId => $pageData) {
                                     //                                        unset($defaults[$langCode]['time_zone'][$timeZoneFlag][$status][$labelId]['ext_identifier']);
                                     //                                        unset($defaults[$langCode]['time_zone'][$timeZoneFlag][$status][$labelId]['ext_value']);
                                     if (!empty($pageData['ext_identifier'])) {
                                         foreach ($pageData['ext_identifier'] as $extIdentifier => $d) {
                                             if ($extIdentifier != "") {
                                                 if (isset($labelProperties) && isset($labelProperties['ext_' . $extIdentifier])) {
                                                     $identifiers[$langCode]['ext_' . $extIdentifier] = $d['ext_value'];
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 //                    dump($defaults);
                 //                    die();
                 //                    dump($allExtensions, $identifiers);
                 //                    die();
                 $newDefaults = \Nette\Utils\Arrays::mergeTree($defaults, $identifiers);
                 //dump($newDefaults);
                 $this->setDefaults($newDefaults);
             }
             //$defaults = $this->presenter->pageManagerService->getDefaults($treeNodeId);
             break;
         case 'addPage':
         case 'addScrap':
             $this->onSuccess[] = array($this, 'addformSubmited');
             if (!$this->isSubmitted()) {
                 //$allLanguages = $this->presenter->langManagerService->getLangs();
                 $defaultLanguage = $this->presenter->langManagerService->getDefaultLanguage();
                 $defaults = $this->presenter->pageModel->getPagesUrls(NULL, array_keys($langs), $defaultLanguage);
                 $defaults['entity'] = $entity;
                 //                    dump($entity);
                 //                    die();
                 if ($label) {
                     //dump($label);
                     $defaults['layout'] = $label['layout'];
                 }
                 if ($this->presenter->preselectedParent !== NULL && !is_array($this->presenter->preselectedParent)) {
                     //$this->addHidden('parent', $this->presenter->preselectedParent);
                     $urls = $this->presenter->pageModel->getPagesUrls($this->presenter->preselectedParent, array_keys($langs), $defaultLanguage);
                     // add urls to defauls (even to nonexisting lang sections!)
                     if (!empty($urls)) {
                         foreach ($urls as $langCode => $parentUrl) {
                             $defaults[$langCode]['parent_url'] = $urls[$langCode]['parent_url'];
                         }
                     }
                 }
                 $this->setDefaults($defaults);
             }
             break;
     }
     $this->onError[] = array($this, 'invalidSubmit');
 }