Ejemplo n.º 1
0
 /**
  * Get object define code
  * @param string $id - object id
  * @return string
  */
 public function getObjectDefineJs($id)
 {
     $eventManager = $this->_project->getEventManager();
     $objectEvents = $eventManager->getObjectEvents($id);
     $object = $this->_project->getObject($id);
     if (!empty($objectEvents)) {
         $eventsConfig = $object->getConfig()->getEvents()->__toArray();
         foreach ($objectEvents as $event => $config) {
             if (empty($config['code'])) {
                 continue;
             }
             $params = '';
             if (isset($eventsConfig[$event])) {
                 $params = implode(',', array_keys($eventsConfig[$event]));
             } elseif (is_array($config['params']) && !empty($config['params'])) {
                 $params = implode(',', array_keys($config['params']));
             }
             $object->addListener($event, Utils_String::addIndent("{\n" . Utils_String::addIndent("fn:function(" . $params . "){\n" . Utils_String::addIndent($config['code']) . "\n},\nscope:this") . "\n}", 2, "\t", true));
         }
     }
     if ($object->isExtendedComponent()) {
         $manager = $this->_project->getMethodManager();
         $objectMethods = $manager->getObjectMethods($id);
         if (!empty($objectMethods)) {
             foreach ($objectMethods as $name => $method) {
                 $object->addMethod($name, $method->getParamsLine(), $method->getCode(), $method->getJsDoc());
             }
         }
         $manager = $this->_project->getEventManager();
         $localEvents = $manager->getLocalEvents($object->getName());
         if (!empty($localEvents)) {
             foreach ($localEvents as $name => $info) {
                 $params = '';
                 $doc = "/**\n * @event " . $name;
                 if (!empty($info['params']) && is_array($info['params'])) {
                     $params = implode(' , ', array_keys($info['params']));
                     foreach ($info['params'] as $key => $type) {
                         $doc .= "\n * @param " . $type . " " . $key;
                     }
                 }
                 $doc .= "\n */";
                 $object->addLocalEvent($name, $params, $doc);
             }
         }
     }
     /**
      * Convert ActionColumn listeners
      */
     if ($object->getClass() === 'Grid') {
         $this->_applycolumnEvents($object);
         $this->_applyFiltersEvents($object->getFiltersFeature());
     }
     return $this->_project->getObject($id)->getDefineJs($this->_project->namespace);
 }
Ejemplo n.º 2
0
 /**
  * Get methods for Ext Object
  * @param string $objectName
  * @return Designer_Project_Methods
  */
 public function getObjectLocalMethods($objectName)
 {
     return $this->_project->getMethodManager($objectName)->getObjectMethods($objectName);
 }
Ejemplo n.º 3
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.º 4
0
    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');
    }