Beispiel #1
0
 /**
  * Load project
  */
 public function loadAction()
 {
     $file = Request::post('file', 'string', false);
     try {
         $project = Designer_Factory::loadProject($this->_config, $file);
     } catch (Exception $e) {
         Response::jsonError($this->_lang->WRONG_REQUEST);
     }
     $this->_session->set('loaded', true);
     $this->_session->set('project', serialize($project));
     $this->_session->set('file', $file);
     Response::jsonSuccess();
 }
Beispiel #2
0
 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;
 }
Beispiel #3
0
 /**
  * Render Designer project
  * @param string $projectFile - file path
  * @param string $renderTo - optional, default false (html tag id)
  */
 public function renderProject($projectFile, $renderTo = false)
 {
     $replaces = $this->getReplaceConfig();
     Designer_Factory::runProject($projectFile, $this->_designerConfig, $replaces, $renderTo);
 }
Beispiel #4
0
 /**
  * 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);
         }
     }
 }
Beispiel #5
0
 /**
  * Compile project js code
  * @param array $replace - optional
  * @return string
  */
 public function getCode($replace = array())
 {
     $codeGen = new Designer_Project_Code($this);
     if (!empty($replace)) {
         return Designer_Factory::replaceCodeTemplates($replace, $codeGen->getCode());
     } else {
         return $codeGen->getCode();
     }
 }
Beispiel #6
0
 /**
  * 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;
 }
Beispiel #7
0
 /**
  * Get list of items for actioncolumn
  */
 public function itemslistAction()
 {
     $designerManager = new Designer_Manager($this->_configMain);
     $object = $this->_object;
     $column = Request::post('column', 'string', false);
     if ($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');
     }
     $result = array();
     $actions = $columnObject->getActions();
     if (!empty($actions)) {
         foreach ($actions as $name => $object) {
             $result[] = array('id' => $name, 'icon' => Designer_Factory::replaceCodeTemplates($designerManager->getReplaceConfig(), $object->icon), 'tooltip' => $object->tooltip);
         }
     }
     Response::jsonSuccess($result);
 }
Beispiel #8
0
    public function indexAction()
    {
        if (!$this->_session->keyExists('loaded') || !$this->_session->get('loaded')) {
            Response::put('');
            exit;
        }
        $designerConfig = Config::factory(Config::File_Array, $this->_configMain['configs'] . 'designer.php');
        $res = Resource::getInstance();
        $res->addJs('/js/lib/jquery.js', 0);
        Model::factory('Medialib')->includeScripts();
        $res->addJs('/js/app/system/SearchPanel.js');
        $res->addJs('/js/app/system/HistoryPanel.js', 0);
        $res->addJs('/js/lib/ext_ux/RowExpander.js', 0);
        $res->addJs('/js/app/system/RevisionPanel.js', 1);
        $res->addJs('/js/app/system/EditWindow.js', 2);
        $res->addJs('/js/app/system/ContentWindow.js', 3);
        $res->addJs('/js/app/system/designer/viewframe/main.js', 4);
        $res->addJs('/js/app/system/designer/lang/' . $designerConfig['lang'] . '.js', 5);
        $project = $this->_getProject();
        $projectCfg = $project->getConfig();
        Ext_Code::setRunNamespace($projectCfg['runnamespace']);
        Ext_Code::setNamespace($projectCfg['namespace']);
        $grids = $project->getGrids();
        if (!empty($grids)) {
            foreach ($grids as $name => $object) {
                if ($object->isInstance()) {
                    continue;
                }
                $cols = $object->getColumns();
                if (!empty($cols)) {
                    foreach ($cols as $column) {
                        $column['data']->itemId = $column['id'];
                    }
                }
                $object->addListener('columnresize', '{
							 fn:function( ct, column, width,eOpts){
								app.application.onGridColumnResize("' . $name . '", ct, column, width, eOpts);
							 }
				}');
                $object->addListener('columnmove', '{
							fn:function(ct, column, fromIdx, toIdx, eOpts){
								app.application.onGridColumnMove("' . $name . '", ct, column, fromIdx, toIdx, eOpts);
							}
				}');
            }
        }
        $dManager = new Dictionary_Manager();
        $key = 'vf_' . md5($dManager->getDataHash() . serialize($project));
        $templates = $designerConfig->get('templates');
        $replaces = array(array('tpl' => $templates['wwwroot'], 'value' => $this->_configMain->get('wwwroot')), array('tpl' => $templates['adminpath'], 'value' => $this->_configMain->get('adminPath')), array('tpl' => $templates['urldelimiter'], 'value' => $this->_configMain->get('urlDelimiter')));
        $includes = Designer_Factory::getProjectIncludes($key, $project, true, $replaces);
        if (!empty($includes)) {
            foreach ($includes as $file) {
                if (File::getExt($file) == '.css') {
                    $res->addCss($file, false);
                } else {
                    $res->addJs($file, false, false);
                }
            }
        }
        $names = $project->getRootPanels();
        $basePaths = array();
        $parts = explode('/', $this->_configMain->get('wwwroot'));
        if (is_array($parts) && !empty($parts)) {
            foreach ($parts as $item) {
                if (!empty($item)) {
                    $basePaths[] = $item;
                }
            }
        }
        $basePaths[] = $this->_configMain['adminPath'];
        $basePaths[] = 'designer';
        $basePaths[] = 'sub';
        //' . $project->getCode($replaces) . '
        $initCode = '
		app.delimiter = "' . $this->_configMain['urlDelimiter'] . '";
		app.admin = "' . $this->_configMain->get('wwwroot') . $this->_configMain->get('adminPath') . '";
		app.wwwRoot = "' . $this->_configMain->get('wwwroot') . '";

		var applicationClassesNamespace = "' . $projectCfg['namespace'] . '";
		var applicationRunNamespace = "' . $projectCfg['runnamespace'] . '";
		var designerUrlPaths = ["' . implode('","', $basePaths) . '"];
		var canDelete = true;
		var canPublish = true;
		var canEdit = true;

		Ext.onReady(function(){
		    app.application.mainUrl = app.createUrl(designerUrlPaths);
            ';
        if (!empty($names)) {
            foreach ($names as $name) {
                if ($project->getObject($name)->isExtendedComponent()) {
                    if ($project->getObject($name)->getConfig()->defineOnly) {
                        continue;
                    }
                    $initCode .= Ext_Code::appendRunNamespace($name) . ' = Ext.create("' . Ext_Code::appendNamespace($name) . '",{});';
                }
                $initCode .= '
			        app.viewFrame.add(' . Ext_Code::appendRunNamespace($name) . ');
			    ';
            }
        }
        $initCode .= '
        	 app.application.fireEvent("projectLoaded");
	   });';
        $res->addInlineJs($initCode);
        $tpl = new Template();
        $tpl->lang = $this->_configMain['language'];
        $tpl->development = $this->_configMain['development'];
        $tpl->resource = $res;
        $tpl->useCSRFToken = Registry::get('backend', 'config')->get('use_csrf_token');
        Response::put($tpl->render(Application::getTemplatesPath() . 'designer/viewframe.php'));
    }