Ejemplo n.º 1
0
 /**
  * @param string $objectName
  * @return array
  */
 public function getObjectEvents($objectName)
 {
     $object = $this->_getObject($objectName);
     $eventManager = $this->_project->getEventManager();
     $objectEvents = $eventManager->getObjectEvents($objectName);
     $data = array();
     if (!empty($objectEvents)) {
         $eventsConfig = $object->getConfig()->getEvents()->__toArray();
         foreach ($objectEvents as $event => $config) {
             if (isset($config['is_local']) && $config['is_local']) {
                 $data[] = array('name' => $event, 'params' => $config['params'], 'value' => $config['code'], 'is_local' => true);
             } else {
                 $data[] = array('name' => $event, 'params' => @$eventsConfig[$event], 'value' => $config['code'], 'is_local' => false);
             }
         }
     }
     return $data;
 }
Ejemplo n.º 2
0
 /**
  * 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);
 }
Ejemplo n.º 3
0
 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();
 }
Ejemplo n.º 4
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;
 }
Ejemplo n.º 5
0
    /**
     * (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;
    }
Ejemplo n.º 6
0
 protected function _compileExtendedSubItems($parent, $mainContainer)
 {
     if (!$this->_project->hasChilds($parent)) {
         return array();
     }
     $mainContainerObject = $this->_project->getItemData($mainContainer);
     $eventManager = $this->_project->getEventManager();
     $childs = $this->_project->getChilds($parent);
     $items = array();
     $docked = array();
     $menu = array();
     foreach ($childs as $k => $item) {
         if ($this->_project->hasChilds($item['id'])) {
             $this->_compileExtendedSubItems($item['id'], $mainContainer);
         }
         $itemName = 'me.childObjects.' . $item['id'];
         switch ($item['data']->getClass()) {
             case 'Docked':
                 if (!$this->_project->hasChilds($item['id'])) {
                     continue;
                 }
                 $docked[] = $item['data'];
                 break;
             case 'Menu':
                 if (!$this->_project->hasChilds($item['id'])) {
                     continue;
                 }
                 $menu[] = $item['data'];
                 break;
             default:
                 $items[] = $itemName;
                 break;
         }
         $objectEvents = $eventManager->getObjectEvents($item['id']);
         if (!empty($objectEvents)) {
             $eventsConfig = $item['data']->getConfig()->getEvents()->__toArray();
             foreach ($objectEvents as $event => $config) {
                 if (empty($config['code'])) {
                     continue;
                 }
                 $params = '';
                 if (isset($eventsConfig[$event])) {
                     $params = implode(',', array_keys($eventsConfig[$event]));
                 }
                 if ($event === 'handler') {
                     $item['data']->addListener($event, "function(" . $params . "){\n" . Utils_String::addIndent($config['code'], 2) . "\n}");
                     $item['data']->scope = 'this';
                 } else {
                     $item['data']->addListener($event, "{\n" . Utils_String::addIndent("fn:function(" . $params . "){\n" . Utils_String::addIndent($config['code'], 2) . "\n},\n" . Utils_String::addIndent("scope:this") . "\n}", 2) . "\n");
                 }
             }
         }
         $mainContainerObject->addElement($itemName, $item['data']);
         /**
          * Convert ActionColumn listeners
          */
         if ($item['data']->getClass() === 'Grid') {
             $this->_applycolumnEvents($item['data']);
             $this->_applyFiltersEvents($item['data']->getFiltersFeature());
         }
     }
     if ($parent !== '0') {
         $container = $this->_project->getItemData($parent);
         if (!empty($items)) {
             $container->items = "[\n" . Utils_String::addIndent(implode(",\n", $items), 1) . "\n]\n";
         }
         if (!empty($docked)) {
             $container->dockedItems = implode(',', $docked);
         }
         if (!empty($menu)) {
             $container->menu = implode(',', $menu);
         }
     }
 }