/** * Conver field from ORM format and add to the project * @param string $name * @param Db_Object_Config $importObject */ protected function _importOrmField($name, $importObjectConfig) { $tabName = $this->_object->getName() . '_generalTab'; if (!$this->_project->objectExists($tabName)) { $tab = Ext_Factory::object('Panel'); $tab->setName($tabName); $tab->frame = false; $tab->border = false; $tab->layout = 'anchor'; $tab->bodyPadding = 3; $tab->bodyCls = 'formBody'; $tab->anchor = '100%'; $tab->autoScroll = true; $tab->title = Lang::lang()->GENERAL; $tab->fieldDefaults = "{\n\t\t\t labelAlign: 'right',\n\t\t\t labelWidth: 160,\n\t\t\t anchor: '100%'\n\t\t\t }"; $this->_project->addObject($this->_object->getName(), $tab); } $tabsArray = array('Component_Field_System_Medialibhtml', 'Component_Field_System_Related', 'Component_Field_System_Objectslist'); $newField = Backend_Designer_Import::convertOrmFieldToExtField($name, $importObjectConfig->getFieldConfig($name)); if ($newField !== false) { $fieldClass = $newField->getClass(); if ($fieldClass == 'Component_Field_System_Objectslist' || $fieldClass == 'Component_Field_System_Objectlink') { $newField->controllerUrl = $this->_object->controllerUrl; } $newField->setName($this->_object->getName() . '_' . $name); if (in_array($fieldClass, $tabsArray, true)) { $this->_project->addObject($this->_object->getName(), $newField); } else { $this->_project->addObject($tabName, $newField); } } }
/** * Conver DB column into Ext field * @param string $name * @param array $config */ protected function _importDbField($name, $config) { $newField = Backend_Designer_Import::convertDbFieldToExtField($config); if ($newField !== false) { $newField->setName($this->_object->getName() . '_' . $name); $this->_project->addObject($this->_object->getName(), $newField); } }
/** * Get events for object */ public function objecteventsAction() { $objectName = $this->_action->getName(); $objectEvents = $this->_project->getEventManager()->getObjectEvents($objectName); $events = $this->_action->getConfig()->getEvents(); $result = array(); $id = 1; foreach ($events as $name => $config) { if (isset($objectEvents[$name]) && !empty($objectEvents[$name])) { $hasCode = true; } else { $hasCode = false; } $result[] = array('id' => $id, 'object' => $objectName, 'event' => $name, 'params' => $this->_convertParams($config), 'has_code' => $hasCode); $id++; } Response::jsonSuccess($result); }
public function allfieldsAction() { $this->_checkLoaded(); $name = Request::post('object', 'string', ''); $project = $this->_getProject(); if (!strlen($name) || !$project->objectExists($name)) { Response::jsonError('Undefined Store object'); } $this->_project = $project; $this->_object = $project->getObject($name); $fields = array(); if ($this->_object->isValidProperty('model') && strlen($this->_object->model) && $this->_project->objectExists($this->_object->model)) { $model = $this->_project->getObject($this->_object->model); if ($model->isValidProperty('fields')) { $fields = $model->fields; if (is_string($fields)) { $fields = json_decode($model->fields, true); } } } if (empty($fields) && $this->_object->isValidProperty('fields')) { $fields = $this->_object->fields; if (empty($fields)) { $fields = array(); } if (is_string($fields)) { $fields = json_decode($fields, true); } } $data = array(); if (!empty($fields)) { foreach ($fields as $item) { if (is_object($item)) { $data[] = array('name' => $item->name, 'type' => $item->type); } else { $data[] = array('name' => $item['name'], 'type' => $item['type']); } } } Response::jsonSuccess($data); }
/** * Get object javascript source code * @param string $name * @return string */ public function getObjectCode($name) { if (!$this->_project->objectExists($name)) { return ''; } $this->applyStoreInstances(); $object = $this->_project->getObject($name); $oClass = $object->getClass(); if (in_array($oClass, Designer_Project::$defines, true) || $object->isExtendedComponent()) { $code = $this->_compileExtendedItem($name, 0); } else { $code = $this->_compileItem($name); } return $code['defines'] . "\n" . $code['layout']; }
public function removeactionAction() { $object = $this->_object; $actionName = Request::post('name', 'alphanum', false); $column = Request::post('column', 'string', false); if ($actionName === false || $column === false) { Response::jsonErrot($this->_lang->WRONG_REQUEST . ' code 1'); } if ($object->getClass() !== 'Grid' || !$object->columnExists($column)) { Response::jsonError($this->_lang->WRONG_REQUEST . ' code 2'); } $columnObject = $object->getColumn($column); if ($columnObject->getClass() !== 'Grid_Column_Action') { Response::jsonError($this->_lang->WRONG_REQUEST . ' code 3'); } $columnObject->removeAction($actionName); $this->_project->getEventManager()->removeObjectEvents($actionName); $this->_storeProject(); Response::jsonSuccess(); }
/** * Get methods for Ext Object * @param string $objectName * @return Designer_Project_Methods */ public function getObjectLocalMethods($objectName) { return $this->_project->getMethodManager($objectName)->getObjectMethods($objectName); }
public function createModule($object, $projectFile, $actionFile) { $lang = Lang::lang(); //prepare class name $name = Utils_String::formatClassName($object); $jsName = str_replace('_', '', $name); $runNamespace = 'app' . $jsName . 'Run'; $classNamespace = 'app' . $jsName . 'Classes'; $objectConfig = Db_Object_Config::getInstance($object); $primaryKey = $objectConfig->getPrimaryKey(); $appConfig = Registry::get('main', 'config'); $designerConfig = Config::factory(Config::File_Array, $appConfig->get('configs') . 'designer.php'); $objectFieldsConfig = $objectConfig->getFieldsConfig(false); $objectFields = array(); $searchFields = array(); $linkedObjects = array(); /* * Skip text fields */ foreach ($objectFieldsConfig as $key => $item) { if ($objectConfig->isObjectLink($key) || $objectConfig->isMultiLink($key)) { $linkedObjects[] = $objectConfig->getLinkedObject($key); } if (in_array($item['db_type'], Db_Object_Builder::$textTypes, true)) { continue; } $objectFields[] = $key; if (isset($item['is_search']) && $item['is_search']) { $searchFields[] = $key; } } $dataFields = array(); foreach ($objectConfig->getFieldsConfig(true) as $key => $item) { if (in_array($item['db_type'], Db_Object_Builder::$textTypes, true)) { continue; } $dataFields[] = $key; } array_unshift($objectFields, $primaryKey); $controllerContent = '<?php ' . "\n" . 'class Backend_' . $name . '_Controller extends Backend_Controller_Crud{' . "\n" . ' protected $_listFields = array("' . implode('","', $dataFields) . '");' . "\n" . ' protected $_canViewObjects = array("' . implode('","', $linkedObjects) . '");' . "\n" . '} '; /* * Create controller */ $controllerDir = $appConfig->get('backend_controllers') . str_replace('_', '/', $name); $this->_createControllerFile($controllerDir, $controllerContent); @chmod($controllerDir . DIRECTORY_SEPARATOR . 'Controller.php', $controllerContent, 0775); /* * Designer project */ $project = new Designer_Project(); $project->namespace = $classNamespace; $project->runnamespace = $runNamespace; /* * Project events */ $eventManager = $project->getEventManager(); $storeFields = Backend_Designer_Import::checkImportORMFields($object, $dataFields); $urlTemplates = $designerConfig->get('templates'); Request::setDelimiter($urlTemplates['urldelimiter']); $controllerUrl = Request::url(array($urlTemplates['adminpath'], $object, ''), false); $storeUrl = Request::url(array($urlTemplates['adminpath'], $object, 'list')); Request::setDelimiter($appConfig->get('urlDelimiter')); $dataStore = Ext_Factory::object('Data_Store'); $dataStore->setName('dataStore'); $dataStore->autoLoad = true; $dataStore->addFields($storeFields); $dataProxy = Ext_Factory::object('Data_Proxy_Ajax'); $dataProxy->type = 'ajax'; $dataReader = Ext_Factory::object('Data_Reader_Json'); $dataReader->root = 'data'; $dataReader->totalProperty = 'count'; $dataReader->idProperty = $primaryKey; $dataReader->type = 'json'; $dataProxy->reader = $dataReader; $dataProxy->url = $storeUrl; $dataProxy->startParam = 'pager[start]'; $dataProxy->limitParam = 'pager[limit]'; $dataProxy->sortParam = 'pager[sort]'; $dataProxy->directionParam = 'pager[dir]'; $dataProxy->simpleSortMode = true; $dataStore->proxy = $dataProxy; $dataStore->remoteSort = true; $project->addObject(0, $dataStore); /* * Data grid */ $dataGrid = Ext_Factory::object('Grid'); $dataGrid->setName('dataGrid'); $dataGrid->store = 'dataStore'; $dataGrid->columnLines = true; $dataGrid->title = $objectConfig->getTitle() . ' :: ' . $lang->HOME; $dataGrid->setAdvancedProperty('paging', true); $dataGrid->viewConfig = '{enableTextSelection: true}'; $eventManager->setEvent('dataGrid', 'itemdblclick', 'show' . $jsName . 'EditWindow(record.get("id"));'); $objectFieldList = Backend_Designer_Import::checkImportORMFields($object, $objectFields); if (!empty($objectFieldList)) { foreach ($objectFieldList as $fieldConfig) { switch ($fieldConfig->type) { case 'boolean': $column = Ext_Factory::object('Grid_Column_Boolean'); $column->renderer = 'Ext_Component_Renderer_System_Checkbox'; $column->width = 50; $column->align = 'center'; break; case 'integer': $column = Ext_Factory::object('Grid_Column'); break; case 'float': $column = Ext_Factory::object('Grid_Column_Number'); if (isset($objectFieldsConfig[$fieldConfig->name]['db_precision'])) { $column->format = '0,000.' . str_repeat('0', $objectFieldsConfig[$fieldConfig->name]['db_precision']); } break; case 'date': $column = Ext_Factory::object('Grid_Column_Date'); if ($objectFieldsConfig[$fieldConfig->name]['db_type'] == 'time') { $column->format = 'H:i:s'; } break; default: $column = Ext_Factory::object('Grid_Column'); } if ($objectConfig->fieldExists($fieldConfig->name)) { $cfg = $objectConfig->getFieldConfig($fieldConfig->name); $column->text = $cfg['title']; } else { $column->text = $fieldConfig->name; } $column->dataIndex = $fieldConfig->name; $column->setName($fieldConfig->name); $column->itemId = $column->getName(); $dataGrid->addColumn($column->getName(), $column, $parent = 0); } } $project->addObject(0, $dataGrid); /* * Top toolbar */ $dockObject = Ext_Factory::object('Docked'); $dockObject->setName($dataGrid->getName() . '__docked'); $project->addObject($dataGrid->getName(), $dockObject); $filters = Ext_Factory::object('Toolbar'); $filters->setName('filters'); $project->addObject($dockObject->getName(), $filters); /* * Top toolbar items */ $addButton = Ext_Factory::object('Button'); $addButton->setName('addButton'); $addButton->text = $lang->ADD_ITEM; $eventManager->setEvent('addButton', 'click', 'show' . $jsName . 'EditWindow(false);'); $project->addObject($filters->getName(), $addButton); $sep1 = Ext_Factory::object('Toolbar_Separator'); $sep1->setName('sep1'); $project->addObject($filters->getName(), $sep1); if (!empty($searchFields)) { $searchField = Ext_Factory::object('Component_Field_System_Searchfield'); $searchField->setName('searchField'); $searchField->width = 200; $searchField->store = $dataStore->getName(); $searchField->fieldNames = json_encode($searchFields); $fill = Ext_Factory::object('Toolbar_Fill'); $fill->setName('fill1'); $project->addObject($filters->getName(), $fill); $project->addObject($filters->getName(), $searchField); } /* * Editor window */ $editWindow = Ext_Factory::object('Component_Window_System_Crud'); $editWindow->setName('editWindow'); $editWindow->objectName = $object; $editWindow->controllerUrl = $controllerUrl; $editWindow->width = 800; $editWindow->height = 650; $editWindow->modal = true; $editWindow->resizable = true; $editWindow->extendedComponent(true); $eventManager->setEvent('editWindow', 'dataSaved', $runNamespace . '.dataStore.load();'); if (!$objectConfig->hasHistory()) { $editWindow->hideEastPanel = true; } $project->addObject(0, $editWindow); $tab = Ext_Factory::object('Panel'); $tab->setName($editWindow->getName() . '_generalTab'); $tab->frame = false; $tab->border = false; $tab->layout = 'anchor'; $tab->bodyPadding = 3; $tab->bodyCls = 'formBody'; $tab->anchor = '100%'; $tab->title = $lang->GENERAL; $tab->autoScroll = true; $tab->fieldDefaults = "{\n\t\t labelAlign: 'right',\n\t\t labelWidth: 160,\n\t\t anchor: '100%'\n\t\t }"; $project->addObject($editWindow->getName(), $tab); $objectFieldList = array_keys($objectConfig->getFieldsConfig(false)); foreach ($objectFieldList as $field) { if ($field == $primaryKey) { continue; } $newField = Backend_Designer_Import::convertOrmFieldToExtField($field, $objectConfig->getFieldConfig($field)); if ($newField === false) { continue; } $newField->setName($editWindow->getName() . '_' . $field); $fieldClass = $newField->getClass(); if ($fieldClass == 'Component_Field_System_Objectslist' || $fieldClass == 'Component_Field_System_Objectlink') { $newField->controllerUrl = $controllerUrl; } if (in_array($fieldClass, $this->tabTypes, true)) { $project->addObject($editWindow->getName(), $newField); } else { $project->addObject($tab->getName(), $newField); } } /* * Save designer project */ $designerStorage = Designer_Factory::getStorage($designerConfig); $project->actionjs = $actionFile; if (!$designerStorage->save($projectFile, $project)) { throw new Exception('Can`t create Designer project'); } /* * Create ActionJS file */ $this->_createActionJS($runNamespace, $classNamespace, $actionFile, $jsName); return true; }
/** * (non-PHPdoc) * @see Backend_Designer_Generator_Component::addComponent() */ public function addComponent(Designer_Project $project, $id, $parentId = false) { $windowName = $project->uniqueId($id); $dockedName = $project->uniqueId($windowName . '__docked'); $toolbarName = $project->uniqueId($windowName . '_bottom_toolbar'); $fillName = $project->uniqueId($windowName . '_footer_fill'); $saveName = $project->uniqueId($windowName . '_footer_saveBtn'); $cancelName = $project->uniqueId($windowName . '_footer_cancelBtn'); $formName = $project->uniqueId($windowName . '_form'); $editWindow = Ext_Factory::object('Window'); $editWindow->setName($windowName); $editWindow->extendedComponent(true); $editWindow->width = 450; $editWindow->height = 500; $editWindow->modal = false; $editWindow->resizable = true; $editWindow->layout = 'fit'; $form = Ext_Factory::object('Form'); $form->setName($formName); $form->bodyCls = 'formBody'; $form->bodyPadding = 5; $form->fieldDefaults = '{anchor:"100%",labelWidth:150}'; $form->autoScroll = true; $dockObject = Ext_Factory::object('Docked'); $dockObject->setName($dockedName); $toolbar = Ext_Factory::object('Toolbar'); $toolbar->setName($toolbarName); $toolbar->dock = 'bottom'; $toolbar->ui = 'footer'; $fill = Ext_Factory::object('Toolbar_Fill'); $fill->setName($fillName); $saveBtn = Ext_Factory::object('Button'); $saveBtn->setName($saveName); $saveBtn->minWidth = 80; $saveBtn->text = '[js:]appLang.SAVE'; $cancelBtn = Ext_Factory::object('Button'); $cancelBtn->setName($cancelName); $cancelBtn->minWidth = 80; $cancelBtn->text = '[js:]appLang.CANCEL'; if (!$project->addObject(false, $editWindow)) { return false; } if (!$project->addObject($windowName, $dockObject)) { return false; } if (!$project->addObject($dockedName, $toolbar)) { return false; } if (!$project->addObject($toolbarName, $fill)) { return false; } if (!$project->addObject($toolbarName, $saveBtn)) { return false; } if (!$project->addObject($toolbarName, $cancelBtn)) { return false; } if (!$project->addObject($windowName, $form)) { return false; } /* * Project events */ $eventManager = $project->getEventManager(); $eventManager->setEvent($cancelName, 'click', 'this.close();'); $eventManager->setEvent($saveName, 'click', 'this.onSaveData();'); $eventManager->setEvent($windowName, 'dataSaved', '', '', true); /* * Project methods */ $methodsManager = $project->getMethodManager(); $m = $methodsManager->addMethod($windowName, 'onSaveData', array(), ' // remove alert, update submit url, set params Ext.Msg.alert(appLang.MESSAGE, "Save button click"); /* // form submit template var me = this; this.childObjects.' . $formName . '.getForm().submit({ clientValidation: true, waitMsg:appLang.SAVING, method:"post", url:"[%wroot%][%admp%][%-%]my_controller[%-%]edit", params:{ }, success: function(form, action) { if(!action.result.success){ Ext.Msg.alert(appLang.MESSAGE, action.result.msg); } else{ me.fireEvent("dataSaved"); me.close(); } }, failure: app.formFailure }); */ '); $m->setDescription('Save data'); return true; }
/** * Get related projects * @param Designer_Project $project * @param array & $list - result */ protected function getRelatedProjects($project, &$list) { $projectConfig = $project->getConfig(); if (isset($projectConfig['files']) && !empty($projectConfig['files'])) { foreach ($projectConfig['files'] as $file) { if (File::getExt($file) === '.js' || File::getExt($file) === '.css') { continue; } $projectFile = $this->_config->get('configs') . $file; $subProject = Designer_Factory::loadProject($this->_config, $projectFile); $list[] = array('project' => $subProject, 'file' => $file); $this->getRelatedProjects($subProject, $list); } } }
/** * Get root panels list * @return array */ public function getRootPanels() { $list = $this->_tree->getChilds(0); $names = array(); if (empty($list)) { return array(); } foreach ($list as $k => $v) { $object = $v['data']; $class = $object->getClass(); if ($class === 'Object_Instance') { $class = $object->getObject()->getClass(); } if (in_array($class, Designer_Project::$_containers, true) && $class !== 'Window' && $class != 'Menu' && !Designer_Project::isWindowComponent($class)) { $names[] = $object->getName(); } } return $names; }
/** * Get list of project components that can be instantiated */ public function caninstantiateAction() { $list = array(); $project = $this->_getProject(); $items = $project->getObjects(); foreach ($items as $name => $object) { if (!$object->isInstance() && $object->isExtendedComponent() && Designer_Project::isVisibleComponent($object->getClass())) { $list[] = array('name' => $name); } } Response::jsonSuccess($list); }
public function addGridMethods(Designer_Project $project, Ext_Object $grid, $object, $vc = false) { $methodsManager = $project->getMethodManager(); $m = $methodsManager->addMethod($grid->getName(), 'initComponent', array(), ' this.addDesignerItems(); this.callParent(); if(!Ext.isEmpty(this.canEdit) && !Ext.isEmpty(this.setCanEdit)){ this.setCanEdit(this.canEdit); }else{ this.canEdit = false; } if(!Ext.isEmpty(this.canDelete) && !Ext.isEmpty(this.setCanDelete)){ this.setCanDelete(this.canDelete); }else{ this.canDelete = false; } if(!Ext.isEmpty(this.canPublish) && !Ext.isEmpty(this.setCanPublish)){ this.setCanPublish(this.canPublish); }else{ this.canPublish = false; } '); $urlTemplates = $this->designerConfig->get('templates'); $deleteUrl = Request::url(array($urlTemplates['adminpath'], $object, 'delete')); $m = $methodsManager->addMethod($grid->getName(), 'deleteRecord', array(array('name' => 'record', 'type' => 'Ext.data.record')), ' Ext.Ajax.request({ url:"' . $deleteUrl . '", method: "post", scope:this, params:{ id: record.get("id") }, success: function(response, request) { response = Ext.JSON.decode(response.responseText); if(response.success){ this.getStore().remove(record); }else{ Ext.Msg.alert(appLang.MESSAGE , response.msg); } }, failure:function(){ Ext.Msg.alert(appLang.MESSAGE, appLang.MSG_LOST_CONNECTION); } }); '); $m->setDescription('Delete record'); $m = $methodsManager->addMethod($grid->getName(), 'setCanEdit', array(array('name' => 'canEdit', 'type' => 'boolean')), ' this.canEdit = canEdit; if(canEdit){ this.childObjects.addButton.show(); }else{ this.childObjects.addButton.hide(); } this.getView().refresh(); '); $m->setDescription('Set edit permission'); $m = $methodsManager->addMethod($grid->getName(), 'setCanDelete', array(array('name' => 'canDelete', 'type' => 'boolean')), ' this.canDelete = canDelete;'); $m->setDescription('Set delete permission'); if ($vc) { $m = $methodsManager->addMethod($grid->getName(), 'setCanPublish', array(array('name' => 'canPublish', 'type' => 'boolean')), 'this.canPublish = canPublish;'); $m->setDescription('Set publish permission'); } $editCode = ' var win = Ext.create("' . $project->namespace . '.editWindow", { dataItemId:id, canDelete:this.canDelete,'; if ($vc) { $editCode .= ' canPublish:this.canPublish,'; } $editCode .= 'canEdit:this.canEdit'; $editCode .= ' }); win.on("dataSaved",function(){ this.getStore().load(); '; if (!$vc) { $editCode .= 'win.close();'; } $editCode .= '},this); win.show(); '; $m = $methodsManager->addMethod($grid->getName(), 'showEditWindow', array(array('name' => 'id', 'type' => 'integer')), $editCode); $m->setDescription('Show editor window'); }
/** * Gel list of JS files to include * (load and render designer project) * @param string $cacheKey * @param Designer_Project $project * @param boolean $selfInclude * @param array $replace * @return array */ public static function getProjectIncludes($cacheKey, Designer_Project $project, $selfInclude = true, $replace = array()) { $applicationConfig = Registry::get('main', 'config'); $designerConfig = Config::factory(Config::File_Array, $applicationConfig->get('configs') . 'designer.php'); $projectConfig = $project->getConfig(); $includes = array(); // include langs if (isset($projectConfig['langs']) && !empty($projectConfig['langs'])) { $language = Lang::getDefaultDictionary(); $lansPath = $designerConfig->get('langs_path'); $langsUrl = $designerConfig->get('langs_url'); foreach ($projectConfig['langs'] as $k => $file) { $file = $language . '/' . $file . '.js'; if (file_exists($lansPath . $file)) { $includes[] = $langsUrl . $file . '?' . filemtime($lansPath . $file); } } } if (isset($projectConfig['files']) && !empty($projectConfig['files'])) { foreach ($projectConfig['files'] as $file) { $ext = File::getExt($file); if ($ext === '.js' || $ext === '.css') { $includes[] = $designerConfig->get('js_url') . $file; } else { $projectFile = $designerConfig->get('configs') . $file; $subProject = Designer_Factory::loadProject($designerConfig, $projectFile); $projectKey = self::getProjectCacheKey($projectFile); $files = self::getProjectIncludes($projectKey, $subProject, true, $replace); unset($subProject); if (!empty($files)) { $includes = array_merge($includes, $files); } } } } Ext_Code::setRunNamespace($projectConfig['runnamespace']); Ext_Code::setNamespace($projectConfig['namespace']); if ($selfInclude) { $layoutCacheFile = Utils::createCachePath($applicationConfig->get('jsCacheSysPath'), $cacheKey . '.js'); /** * @todo remove slow operation */ if (!file_exists($layoutCacheFile)) { file_put_contents($layoutCacheFile, Code_Js_Minify::minify($project->getCode($replace))); } $includes[] = str_replace('./', '/', $layoutCacheFile); } /* * Project actions */ $actionFile = $project->getActionsFile(); /** * @todo slow operation */ $mTime = 0; if (file_exists('.' . $actionFile)) { $mTime = filemtime('.' . $actionFile); } $includes[] = $actionFile . '?' . $mTime; return $includes; }