Example #1
0
 public function loadButtons()
 {
     $buttons = Zend_Controller_Front::getInstance()->getRequest()->getParam('buttons');
     if (!count($buttons)) {
         $buttons = array();
     }
     if (!$buttons['Salvar']) {
         $edit = Zend_Controller_Front::getInstance()->getRequest()->getParam('edit');
         $success = "";
         if (!$edit) {
             $success = "location.reload();";
         } else {
             $success = "window.location.href = \$('#content-button-edit').attr('href');";
         }
         $onClick = "function(){\n                                var form = jQuery('#" . $this->_formNome . "');\n                                jQuery.AjaxT.submitJson({\n                                    selector: form,\n                                    success: function(result){\n                                        {$success}\n                                    }\n                                });\n                            }";
         $_button = new ZendT_Form_Element_Button('salvar-dynamic');
         $_button->setIcon('ui-icon-check');
         $_button->addClass('btn btn-primary');
         $_button->setLabel('Salvar');
         $_button->setAttrib('onClick', new ZendT_JS_Command($onClick));
         $_button->addDecorator(new ZendT_Form_Decorator_Button());
         $_button->addStyle('float', 'right');
         $this->addElement($_button);
         /* $buttons['Salvar'] = $_button;
            Zend_Controller_Front::getInstance()->getRequest()->setParam('buttons', $buttons); */
     }
 }
Example #2
0
 /**
  * Carrega os elementos no formulário para serem renderizado
  * @return void
  */
 public function loadElements()
 {
     $this->setName('frm_auth');
     $this->setAction(ZendT_Url::getBaseUrl() . '/auth/user/authenticate');
     $_elements = new Auth_Form_Usuario_Elements();
     $element = $_elements->getLogin();
     $element->setLabel(_i18n('E-Mail'));
     $element->setRequired(true);
     $this->addElement($element);
     $element = $_elements->getSenha();
     $element->setRequired(true);
     $this->addElement($element);
     $element = new ZendT_Form_Element_Button('btn_auth');
     $element->setIcon('ui-icon-check');
     $element->setLabel(_i18n('Autenticar'));
     $element->setAttrib('onClick', 'jQuery.AjaxT.submitJson({selector: \'#frm_auth\', success: function(result){console.log(result);}})');
     $this->addElement($element);
 }
Example #3
0
 /**
  * Ação :: Formulário de Inclusão e Alteração
  */
 public function formAction()
 {
     $this->_form = new $this->_formName();
     $module = $this->getRequest()->getModuleName();
     $controller = $this->getRequest()->getControllerName();
     $params = $this->getRequest()->getParams();
     $action = $params['action_form'];
     if ($params['typeModal'] == 'AJAX') {
         Zend_Layout::getMvcInstance()->setLayout('ajax');
     } else {
         if ($params['typeModal'] == 'IFRAME') {
             Zend_Layout::getMvcInstance()->setLayout('iframe');
         } else {
             if ($params['typeModal'] == 'WINDOW') {
                 Zend_Layout::getMvcInstance()->setLayout('window');
             }
         }
     }
     $this->view->onLoad = stripslashes(urldecode($params['afterLoad']));
     if (substr($this->view->onLoad, 0, 7) == 'base64:') {
         $this->view->onLoad = base64_decode(substr($this->view->onLoad, 7));
     }
     $event = 'insert';
     $actionForm = Zend_Controller_Front::getInstance()->getRequest()->getParam('action_form');
     if ($actionForm) {
         $event = $actionForm;
     }
     $this->getForm()->loadElements($event);
     if ($params['id']) {
         $row = $this->_retrieve();
         $this->getForm()->populate($row);
     }
     $_buttons = array();
     $first = true;
     if (count($params['buttons']) > 0) {
         foreach ($params['buttons'] as $caption => $button) {
             $_button = array();
             $_button['caption'] = $caption;
             $_button['icon'] = $button['icon'];
             $_button['onClick'] = $button['onClick'];
             if ($first) {
                 $first = false;
                 $_button['class'] = 'btn primary';
             }
             $_buttons[] = $_button;
         }
     } else {
         if (!$params['grid']) {
             $formParams = array();
             if ($params['callback']) {
                 $params['callback'] = urldecode($params['callback']);
                 if (substr($params['callback'], 0, 7) == 'base64:') {
                     $params['callback'] = base64_decode(substr($params['callback'], 7));
                 }
                 if ($params['callback']) {
                     $formParams['success'] = new ZendT_JS_Command($params['callback']);
                 }
             }
             $formParams = ZendT_JS_Json::encode($formParams);
             $_button = array();
             $_button['caption'] = _i18n('Salvar');
             $_button['icon'] = 'ui-icon-disk';
             $_button['onClick'] = "function(){" . "   var form = jQuery('#" . $this->getForm()->getName() . "'); " . "   form.TForm('save'," . $formParams . ");" . "}";
             $_button['class'] = 'btn primary';
             $_buttons[] = $_button;
         }
     }
     $this->getForm()->loadElements($event);
     $profile = ZendT_Profile::get($this->_formName, 'F');
     /**
      * Utiliza o profile cadastrado, do contrário utiliza o Form Default
      */
     if ($profile) {
         $this->getForm()->loadProfile($profile);
     }
     $listProfile = ZendT_Profile::listProfile($this->_formName, 'F');
     $_profile = new ZendT_View_Profile('selProfile', $profile['id'], $listProfile, 'F', $this->_formName);
     $screenName = $this->view->screenName;
     $this->view->profileMenu = $_profile->render($screenName);
     $this->view->screenName = $screenName;
     $this->view->placeholder('title')->set($screenName);
     /* $screenName = $_profile->render($this->view->screenName);
        $this->view->screenName = $screenName;
        $this->view->placeholder('title')->set($screenName); */
     $this->getForm()->populate($params);
     $hasAction = $this->getForm()->setAction($action);
     if (!$hasAction) {
         $action = ZendT_Url::getBaseUrl() . '/' . $module . '/' . $controller . '/' . $action;
         $this->getForm()->setAction($action);
     }
     $buttons = $this->_createButtons($_buttons);
     $this->view->buttonsLoad = $buttons['buttons'];
     $buttons['buttons'] = $buttons['buttons'];
     $this->view->buttons = $buttons;
     $this->view->grid = '';
     if ($params['grid']) {
         $configColumns = $this->_mapper->getColumns()->toArray();
         foreach ($configColumns as $column => $key) {
             if ($key['subtotal']) {
                 $this->getGrid()->setFooterRow(true);
                 $this->getGrid()->setUserDataOnFooter(true);
                 break;
             }
         }
         $this->getColumns();
         $this->configGrid();
         $onCellSelect = "function(){\n                                    var grid  = jQuery('#" . $this->getGrid()->getID() . "');\n                                    var id = grid.jqGrid('getGridParam','selrow');\n                                    jQuery('#" . $this->getForm()->getName() . "').TForm('retrieve',id);\n                                }";
         $this->getGrid()->setOnCellSelect($onCellSelect);
         $this->getGrid()->setObjToolbar(null);
         /* getObjToolbar()->removeButton('add');
            $this->getGrid()->getObjToolbar()->removeButton('edit'); */
         //$this->getGrid()->getT
         //                      getToolbarButton('edit')
         $this->view->grid = $this->getGrid();
         $_element = new ZendT_Form_Element_Button('btn_save');
         $_element->setLabel('Salvar');
         $_element->setIcon('ui-icon ui-icon-disk');
         $_element->setAttrib('onClick', "jQuery('#" . $this->getForm()->getName() . "').TForm('save',{grid: '#" . $this->getGrid()->getID() . "'});");
         $this->getForm()->addElement($_element);
         $_element = new ZendT_Form_Element_Button('btn_new');
         $_element->setLabel('Novo');
         $_element->setIcon('ui-icon ui-icon-document');
         $_element->setAttrib('onClick', "jQuery('#" . $this->getForm()->getName() . "').TForm('clear',{});");
         $this->getForm()->addElement($_element);
         if (ZendT_Acl::getInstance()->isAllowed('delete', $this->_resourceBase)) {
             $_element = new ZendT_Form_Element_Button('btn_delete');
             $_element->setLabel('Excluir');
             $_element->setIcon('ui-icon ui-icon-trash');
             $_element->setAttrib('onClick', "jQuery('#" . $this->getForm()->getName() . "').TForm('delete',{grid: '#" . $this->getGrid()->getID() . "'});");
             $this->getForm()->addElement($_element);
         }
         $_element = new ZendT_Form_Element_Button('btn_next');
         $_element->setIcon('ui-icon ui-icon-seek-next');
         $_element->addStyle('float', 'right');
         $_element->addClass('ui-button-icon ui-state-default ui-group-item item last');
         $_element->setAttrib('onClick', "jQuery('#" . $this->getForm()->getName() . "').TForm('navByGrid',{grid: '#" . $this->getGrid()->getID() . "',move:'next'});");
         $this->getForm()->addElement($_element);
         $_element = new ZendT_Form_Element_Button('btn_prev');
         $_element->setIcon('ui-icon ui-icon-seek-prev');
         $_element->addStyle('float', 'right');
         $_element->addClass('ui-button-icon ui-state-default ui-group-item item first');
         $_element->setAttrib('onClick', "jQuery('#" . $this->getForm()->getName() . "').TForm('navByGrid',{grid: '#" . $this->getGrid()->getID() . "',move:'prev'});");
         $this->getForm()->addElement($_element);
         $this->getForm()->addDisplayGroup(array('btn_save', 'btn_new', 'btn_delete', 'btn_next', 'btn_prev'), 'group-nav-buttons', array('id' => 'group-nav-buttons-' . $this->getForm()->getName(), 'class' => 'ui-nav-form'));
     }
     $this->view->form = $this->getForm();
 }