/** * Cria um campo texto com validador de data e datepicker * * @param string $id * @param string $value * @param array $params jQuery Widget Parameters * @param array $attribs HTML Element Attributes * @return string */ public function dateDynamic($id, $value = null, array $attribs = array()) { $params = $attribs['jQueryParams']; unset($attribs['jQueryParams']); $params['helper_script'] = 'TDateDynamic'; $data = date('dmy'); $this->view->headScript()->appendFile(ZendT_Url::getBaseDiretoryPublic() . '/layout/jquery/widget/TDateDynamic.js?' . $data); $this->view->headScript()->appendFile(ZendT_Url::getBaseDiretoryPublic() . '/layout/jquery/widget/TButtonsDynamic.js?' . $data); $this->jquery->addOnLoad('jQuery("#' . $id . '").TButtonsDynamic(' . ZendT_JS_Json::encode($params) . ');'); $attribs['style'] .= 'float:left;'; $attribs['class'] .= ' ui-input-date item'; return '<div class="ui-form-group">' . $this->view->formText($id, $value, $attribs) . '</div>'; }
/** * Renderiza os dados para JSON no formato RPC * * @return string */ public function toRpc($id = '') { //{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"} $jsonrpc = array('jsonrpc' => '2.0', 'id' => $id, 'error' => array()); if ($this->_error === true) { $jsonrpc['error']['code'] = $this->_data['exception']['code']; $jsonrpc['error']['message'] = $this->_data['exception']['message']; $jsonrpc['error']['notification'] = $this->_data['exception']['notification']; } else { $jsonrpc['result'] = $this->_data; } return ZendT_JS_Json::encode($jsonrpc); }
/** * @param array $data * @return string */ public static function encode($data, $defaultQuote = true) { $result = ''; if ($defaultQuote) { $quote = '"'; } if (!is_array($data) && !is_object($data)) { return $data; } else { foreach ($data as $key => $value) { if ($value instanceof ZendT_Type) { $value = $value->get(); } if (is_numeric($value) && strlen((int) $value) == strlen($value)) { $result .= ',' . $quote . $key . $quote . ': ' . $value; } else { if (is_bool($value)) { $result .= ',' . $quote . $key . $quote . ': ' . ($value ? 'true' : 'false'); } else { if ($value instanceof ZendT_JS_Command) { $result .= ',' . $quote . $key . $quote . ': ' . $value->render(); } else { if (is_array($value) || is_object($value)) { $result .= ',' . $quote . $key . $quote . ': ' . ZendT_JS_Json::encode($value, $defaultQuote); } else { // Escape these characters with a backslash: // " \ / \n \r \t \b \f $search = array('\\', "\n", "\t", "\r", "\\b", "\f", '"', '/'); $replace = array('\\\\', '\\n', '\\t', '\\r', '\\b', '\\f', '\\"', '\\/'); $value = str_replace($search, $replace, $value); // Escape certain ASCII characters: // 0x08 => \b // 0x0c => \f $value = str_replace(array(chr(0x8), chr(0xc)), array('\\b', '\\f'), $value); $result .= ',' . $quote . $key . $quote . ': "' . $value . '"'; } } } } } } return '{' . substr($result, 1) . '}'; }
/** * Cria um campo texto com autocomplete customizado * * @param string $id * @param string $value * @param array $params jQuery Widget Parameters * @param array $attribs HTML Element Attributes * @return string */ public function autocomplete($id, $value = null, array $attribs = array()) { $params = $attribs['jQueryParams']; unset($attribs['jQueryParams']); if (!isset($params['source'])) { if (isset($params['url'])) { $params['source'] = $params['url']; unset($params['url']); } else { if (isset($params['data'])) { $params['source'] = $params['data']; unset($params['data']); } else { require_once "ZendX/JQuery/Exception.php"; throw new ZendX_JQuery_Exception("O parametro Source é obrigatório"); } } } if ($params['showButtonSearch']) { $xhtml = '<button id="search-' . $id . '" type="button" class="ui-button ui-state-default item" nofocus="true"><span class="ui-icon ui-icon-carat-1-s"></span></button>'; } else { $xhtml = ''; } $xscript = ''; if ($params['multiple']) { $onResult = 'function(event, row, formatted){ jQuery("#' . $id . '").Tdata("TAutocomplete").addElement("' . $id . '", row[0]); }'; $params['onResult'] = new ZendT_JS_Command($onResult); $xhtml .= '<div id="sel-elements-' . $id . '" class="" style="text-wrap: normal;"> <input id="' . $id . '-multiple" name="' . $id . '-multiple" type="hidden" value=""> </div>'; $xscript .= 'jQuery("#sel-elements-' . $id . '").width(jQuery("#' . $id . '").width());'; } $this->view->headScript()->appendFile(ZendT_Url::getBaseDiretoryPublic() . '/scripts/jquery/extra/jquery.autocomplete.js'); $this->view->headLink()->appendStylesheet(ZendT_Url::getBaseDiretoryPublic() . '/scripts/jquery/extra/jquery.autocomplete.css'); $this->view->headScript()->appendFile(ZendT_Url::getBaseDiretoryPublic() . '/scripts/jquery/widget/TAutocomplete.js'); $params = ZendT_JS_Json::encode($params); $params = str_replace('{id}', $id, $params); $this->jquery->addOnLoad('jQuery("#' . $id . '").TAutocomplete(' . $params . ');' . $xscript); $attribs['class'] .= ' item'; return '<div class="ui-form-group"> ' . $this->view->formText($id, $value, $attribs) . $xhtml . '</div>'; }
public function spreadSheet($id, $value = null, array $attribs = array()) { #var_dump($attribs);die; $params = $attribs['jQueryParams']; #var_dump($params);die; unset($attribs['jQueryParams']); $xhtml = "<div id='{$id}'"; if ($attribs['divParams']) { foreach ($attribs['divParams'] as $key => $val) { $xhtml .= " {$key}='{$val}'"; } } $xhtml .= "><input type=\"hidden\" TSpreadSheet=\"1\" id=\"{$id}_json\" name=\"{$id}\" /></div>"; $params['elements']['id'] = $id; $this->view->headScript()->appendFile(ZendT_Url::getBaseDiretoryPublic() . '/scripts/jquery/extra/handsontable-master/dist/handsontable.full.js?'); $this->view->headLink()->appendStylesheet(ZendT_Url::getBaseDiretoryPublic() . '/scripts/jquery/extra/handsontable-master/dist/handsontable.full.css'); $this->view->headScript()->appendFile(ZendT_Url::getBaseDiretoryPublic() . "/scripts/jquery/widget/TSpreadSheet.js?date=" . strtotime("now")); $this->jquery->addOnLoad('jQuery("#' . $id . '").TSpreadSheet(' . ZendT_JS_Json::encode($params) . ');'); return $xhtml; }
public function query($id, $value = null, array $attribs = array()) { $_mapperView = $attribs['mapperView']; if (!$_mapperView instanceof ZendT_Db_View) { $_mapperView = new $_mapperView(); } $columns = $_mapperView->getColumns()->toQuery(); $_parse = new ZendT_Db_Adapter_ParseSQL(); $command = $_parse->toArray($value); $param = array(); $param['jsonElement'] = $command; $param['columns'] = $columns; $param['mapper'] = get_class($_mapperView); $param['urlQuote'] = ZendT_Url::getUri(true) . '/quote'; $urlPublic = ZendT_Url::getBaseDiretoryPublic(); $this->view->headScript()->appendFile($urlPublic . '/scripts/jquery/widget/TQueryBuilder.js'); $this->view->headLink()->appendStylesheet($urlPublic . '/scripts/jquery/widget/TQueryBuilder/TQueryBuilder.css'); $js = "jQuery('#{$id}').TQueryBuilder(" . ZendT_JS_Json::encode($param) . ");"; $this->jquery->addOnLoad($js); return $this->view->formHidden($id, $value, $attribs); }
/** * Retorna a função javascript * * @return string */ public function createJS() { $onClick = $this->getOnClick(); $param = array(); if ($onClick instanceof ZendT_JS_Command) { $param['onClick'] = $onClick; } $js = " jQuery('#{$this->getId()}').TButton(" . ZendT_JS_Json::encode($param) . "); "; $this->addOnLoad($this->getId(), $js); $this->addHeadScriptFile(ZendT_Url::getBaseDiretoryPublic() . '/scripts/jquery/widget/TButton.js'); return $js; }
/** * 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(); }
/** * Cria cria um campo hidden, um campo para id, um para descrição e um botão para a busca no seeker. * * @param string $id * @param string $value * @param array $params jQuery Widget Parameters * @param array $attribs HTML Element Attributes * @return string */ public function fileUpload($id, $value = null, array $attribs = array()) { /* echo '<pre>'; print_r($attribs); echo '</pre>'; exit; */ if ($value instanceof ZendT_Type_FileSystem) { $_file = $value->getFile(); if ($_file) { $attribs['jQueryParams']['data']['name'] = $_file->getName(); $attribs['jQueryParams']['data']['type'] = $_file->getType(); $attribs['jQueryParams']['data']['id'] = $_file->getId(); $attribs['jQueryParams']['data']['filename'] = $_file->toFilenameCrypt(); $value = $_file->getName(); } else { $value = ""; } } $params = $attribs['jQueryParams']; unset($attribs['jQueryParams']); if (!isset($attribs['name'])) { $attribs['name'] = $attribs['id']; } $params['url']['base'] = ZendT_Url::getBaseUrl(); $params['url']['public'] = ZendT_Url::getBaseDiretoryPublic(); $id = $this->view->escape($id); $name = $this->view->escape($attribs['name']); $list = '<ul id="' . $id . '_menu" class="dropdown-menu position" role="' . $id . '" style="width: 270px;">'; $list .= ' <li class="ui-no-hover dropdown-menu-group footer">'; $list .= ' <ul class="facescroll" style="width: 260px; height: 130px;" id="files-selected-' . $id . '">'; $list .= ' </ul>'; $list .= ' <button type="button" id="clear-files-' . $id . '" class="ui-button ok ui-state-default">'; $list .= ' <span class="ui-icon ui-icon-close"></span>'; $list .= ' <span class="ui-text">Limpar</span>'; $list .= ' </button>'; $list .= ' '; $list .= ' </li>'; $list .= '</ul>'; $inputAuto = "ui-input-auto"; $xhtml = '<input style="width: 270px;" type="text" id="' . $id . '" name="' . $name . '_display" class="item ' . $inputAuto . '" placeholder="' . $value . '" />'; if ($params['load_id']) { $xhtml .= '<input type="hidden" name="' . $name . '[id]" id="' . $id . '_id" /> <input type="hidden" name="' . $name . '[file]" id="' . $id . '_file" /> <input type="hidden" name="' . $name . '[type]" id="' . $id . '_type" /> <input type="hidden" name="' . $name . '[name]" id="' . $id . '_name" />'; } else { $nameType = $this->_prepareName($name, 'type'); $nameName = $this->_prepareName($name, 'name'); $nameId = $this->_prepareName($name, 'id'); $xhtml .= '<input type="hidden" name="' . $name . '" id="' . $id . '_file" /> <input type="hidden" name="' . $nameType . '" id="' . $id . '_type" /> <input type="hidden" name="' . $nameName . '" id="' . $id . '_name" /> <input type="hidden" name="' . $nameId . '" id="' . $id . '_id" />'; } /* if ($params['multiple']) { $xhtml.= $list; $xhtml.= '<button type="button" id="dropdown-files-' . $id . '" class="ui-button item ui-state-default"><span class="ui-icon ui-icon ui-icon-triangle-1-s"></button>'; } else { $xhtml.= '<button type="button" id="download-files-' . $id . '" class="ui-button item ui-state-default"><span class="ui-icon ui-icon-arrowthickstop-1-s"></button>'; $xhtml.= '<button type="button" id="clear-files-' . $id . '" class="ui-button item ui-state-default"><span class="ui-icon ui-icon-close"></button>'; } */ $xhtml .= $list; //$xhtml.= '<button type="button" id="dropdown-files-' . $id . '" class="ui-button item ui-state-default"><span class="ui-icon ui-icon ui-icon-triangle-1-s"></button>'; $xhtml .= '<button type="button" id="select-files-' . $id . '" class="ui-button item ui-state-default"><span class="ui-icon ui-icon-folder-open"></button>'; $xhtml .= '<div style="clear:both">'; $xhtml .= ' <label class="error" id="error-' . $id . '"></label>'; $xhtml .= '</div>'; $params['elements']['container'] = 'group-' . $id; $params['elements']['files-selected'] = 'files-selected-' . $id; $params['elements']['selectFiles'] = 'select-files-' . $id; $params['elements']['clearFiles'] = 'clear-files-' . $id; $params['elements']['startUpload'] = 'start-upload-' . $id; $params['elements']['id'] = $id; $this->view->headScript()->appendFile(ZendT_Url::getBaseDiretoryPublic() . '/scripts/plupload/plupload.js'); $this->view->headScript()->appendFile(ZendT_Url::getBaseDiretoryPublic() . '/scripts/plupload/plupload.gears.js'); $this->view->headScript()->appendFile(ZendT_Url::getBaseDiretoryPublic() . '/scripts/plupload/plupload.silverlight.js'); $this->view->headScript()->appendFile(ZendT_Url::getBaseDiretoryPublic() . '/scripts/plupload/plupload.flash.js'); $this->view->headScript()->appendFile(ZendT_Url::getBaseDiretoryPublic() . '/scripts/plupload/plupload.html4.js'); $this->view->headScript()->appendFile(ZendT_Url::getBaseDiretoryPublic() . '/scripts/plupload/plupload.html5.js'); $this->view->headScript()->appendFile(ZendT_Url::getBaseDiretoryPublic() . '/layout/jquery/widget/TJQuery.js'); $this->view->headScript()->appendFile(ZendT_Url::getBaseDiretoryPublic() . '/layout/jquery/widget/TFileUpload.js'); $this->view->headScript()->appendFile(ZendT_Url::getBaseDiretoryPublic() . '/layout/jquery/widget/TDropdown.js'); $this->jquery->addOnLoad('jQuery("#' . $id . '").TFileUpload(' . ZendT_JS_Json::encode($params) . ');'); //if ($params['multiple']) { $this->jquery->addOnLoad('jQuery("#' . $id . '_menu").TDropdown({configsHideShow:{events:[\'focus\']}});'); //} return '<div class="ui-form-group">' . $xhtml . '</div>'; }
/** * Cria um campo texto com autocomplete customizado * * @param string $id * @param string $value * @param array $params jQuery Widget Parameters * @param array $attribs HTML Element Attributes * @return string */ public function autoselect($id, $value = null, array $attribs = array()) { $params = $attribs['jQueryParams']; $attribs['class'] .= ' ui-input-auto'; unset($attribs['jQueryParams']); unset($attribs['autocomplete']); unset($attribs['options']); unset($attribs['button']); //unset($attribs['fields']); unset($attribs['propId']); unset($attribs['propSearch']); unset($attribs['autoComplete']); unset($attribs['belongsTo']); /*echo '<pre>'; print_r($attribs); echo '</pre>';*/ $this->view->headScript()->appendFile(ZendT_Url::getBaseDiretoryPublic() . '/layout/jquery/widget/TAutoSelect.js'); $params = array(); $fields = array(); foreach ($attribs['fields'] as $field) { array_push($fields, $field); } if ($attribs['mapperView']) { $_mapper = new $attribs['mapperView'](); $_where = new ZendT_Db_Where(); if ($attribs['where']) { if (substr($attribs['where'], 0, 11) == 'expression:') { $_where->addFilter(' ', substr($attribs['where'], 11), 'EXPRESSION'); } else { $_where->addFilter('id', $attribs['where']); } } if ($attribs['fieldLevel']) { $fields[] = $attribs['fieldLevel']; } if ($attribs['fieldOrder']) { $order = $attribs['fieldOrder']; } else { $order = $fields[1]; } Zend_Controller_Front::getInstance()->getRequest()->setParam('autoselectFilter', true); $_mapper->findAll($_where, $fields, $order); Zend_Controller_Front::getInstance()->getRequest()->setParam('autoselectFilter', false); $sourceData = array(); while ($_mapper->fetch()) { $data = $_mapper->getData(); $row = array(); $row['value'] = $data[$fields[0]]->get(); $row['desc'] = $data[$fields[1]]->get(); if ($attribs['fieldLevel']) { $row['level'] = $data[$fields[2]]->toPhp(); } else { $row['level'] = 0; } $sourceData[] = $row; if ($value == $row['value']) { $params['loadValue'] = $row['desc']; } } } if (isset($attribs['sourceData'])) { $sourceData = $attribs['sourceData']; unset($attribs['sourceData']); } /*if (count($sourceData) == 0 || !is_array($sourceData)){ throw new ZendT_Exception('Propriedade "sourceData" não definida!'); }*/ if ($attribs['suffix']) { $nameId = 'id_' . $attribs['suffix']; } if ($attribs['prefix']) { $nameId = $attribs['prefix'] . '_id'; } /** * @todo encontrar a melhor maneira de implementação */ $required = $attribs['required']; $attribs['class'] = str_replace('required', '', $attribs['class']); unset($attribs['fields']); unset($attribs['mapperView']); unset($attribs['suffix']); unset($attribs['prefix']); unset($attribs['caption']); unset($attribs['required']); unset($attribs['where']); unset($attribs['fieldLevel']); unset($attribs['fieldOrder']); $params['sourceData'] = $sourceData; $params['fieldValue'] = $nameId; $attribs['TAutoSelect'] = '1'; $attribs['role'] = ''; //var_dump($params); $params = ZendT_JS_Json::encode($params); $this->jquery->addOnLoad('jQuery("#' . $id . '").TAutoSelect(' . $params . ');'); return $this->view->formText($id, '', $attribs) . $this->view->formHidden($nameId, '', array('required' => $required, 'TAutoSelect' => '1', 'role' => $id)); }
/** * * @param string $content * @return string */ public function seeker($id, $value = null, array $attribs = array()) { if ($value == '!') { $value = ''; } if ($value && (is_numeric($value) || $value instanceof ZendT_Type) && isset($attribs['mapperView']) && !$value instanceof ZendT_Db_Recordset) { $mapper = new $attribs['mapperView'](); $value = $mapper->setId($value)->retrieveRow(); } if ($value instanceof ZendT_Db_Recordset) { $data = array(); while ($row = $value->getRow()) { $item = array(); foreach ($row as $itemKey => $itemValue) { $item[$itemKey] = $itemValue->get(); } $data[] = $item; } $value = $data; if (!$attribs['multiple']) { $value = $value[0]; } } /* $post = Zend_Controller_Front::getInstance()->getRequest()->getParams(); var_dump($post); var_dump($value); */ $params = array(); $params['elements'] = array(); /** * @todo implementar o value */ $search = $attribs['propSearch']; $suffix = $attribs['suffix']; $prefix = $attribs['prefix']; $this->_arrayName = $attribs['arrayName']; if (!$suffix && !$prefix) { $suffix = $id; } if ($attribs['required']) { $search->setRequired(); } $xhtmlElements = ''; $labels = array(); /** * Cria o elemento de Search */ $field = $attribs['propSearch']->getAttrib('field'); $attribs['propSearch']->setAttrib('noLabelError', true); $params['fields'][] = $field; if (isset($attribs['belongsTo'])) { $attribs['propSearch']->setBelongsTo($attribs['belongsTo']); } if (isset($attribs['style'])) { $attribs['propSearch']->setAttrib('style', $attribs['style']); } if (isset($attribs['readonly'])) { $attribs['propSearch']->setAttrib('readonly', $attribs['readonly']); } $xhtmlElements .= $this->_renderElement($attribs['propSearch'], $value, $suffix, $prefix); unset($attribs['fields'][$field]); $searchId = $attribs['propSearch']->getId(); $labels[] = $attribs['propSearch']->getAttrib('label'); if (isset($attribs['propDisplay'])) { $labels[] = $attribs['propDisplay']->getAttrib('label'); } /** * */ $renderKeys = array('propId', 'propDisplay'); foreach ($renderKeys as $key) { if (isset($attribs[$key])) { $field = $attribs[$key]->getAttrib('field'); $params['fields'][] = $field; if (isset($attribs['belongsTo'])) { $attribs[$key]->setBelongsTo($attribs['belongsTo']); } $xhtmlElements .= $this->_renderElement($attribs[$key], $value, $suffix, $prefix, $searchId); if ($key == 'propId') { $nameId = $attribs['propId']->getId(); } unset($attribs['fields'][$field]); } } $params['elements']['others'] = array(); foreach ($attribs['fields'] as $field) { $key = 'prop' . ucfirst($field); $labels[] = $attribs[$key]->getAttrib('label'); if (isset($attribs['belongsTo'])) { $attribs[$key]->setBelongsTo($attribs['belongsTo']); } $xhtmlElements .= $this->_renderElement($attribs[$key], $value, $suffix, $prefix, $searchId); $params['fields'][] = $field; $params['elements']['others'][] = $attribs[$key]->getId(); unset($attribs[$key]); } if (isset($attribs['btn_add'])) { $attribs['btn_add']->addClass('ui-button item ui-state-default'); if ($suffix) { $nameButton = $attribs['btn_add']->getName(); $nameButton .= '_' . $suffix; $attribs['btn_add']->setName($nameButton); } if ($prefix) { $nameButton = $prefix . '_' . $attribs['btn_add']->getName(); $attribs['btn_add']->setName($nameButton); } $attribs['btn_add']->setAttrib('searchId', $searchId); $xhtmlElements .= $attribs['btn_add']->render(); $params['elements']['btn_add'] = $attribs['btn_add']->getId(); } if (isset($attribs['btn_edit'])) { $attribs['btn_edit']->addClass('ui-button item ui-state-default'); if ($suffix) { $nameButton = $attribs['btn_edit']->getName(); $nameButton .= '_' . $suffix; $attribs['btn_edit']->setName($nameButton); } if ($prefix) { $nameButton = $prefix . '_' . $attribs['btn_edit']->getName(); $attribs['btn_edit']->setName($nameButton); } $attribs['btn_edit']->setAttrib('searchId', $searchId); $xhtmlElements .= $attribs['btn_edit']->render(); $params['elements']['btn_edit'] = $attribs['btn_edit']->getId(); } $attribs['button']->addClass('ui-button item ui-state-default last'); if ($suffix) { $nameButton = $attribs['button']->getName(); $nameButton .= '_' . $suffix; $attribs['button']->setName($nameButton); } if ($prefix) { $nameButton = $prefix . '_' . $attribs['button']->getName(); $attribs['button']->setName($nameButton); } $attribs['button']->setAttrib('searchId', $searchId); $xhtmlElements .= $attribs['button']->render(); $params['elements']['div'] = str_replace('btSearch_', 'div_grid_', $nameButton); $xhtmlElements .= '<div id="' . $params['elements']['div'] . '" style="display:none" class="div-grid-seeker" searchId="' . $searchId . '"></div>'; $xhtmlElements .= '<label class="error" for="' . $searchId . '" generated="true" style="display:none"></label>'; if ($attribs['multiple']) { $xhtmlElements .= '<input type="hidden" name="' . $nameId . '-multiple" id="' . $nameId . '-multiple" />'; $tableTitles = '<tr id="table-title-' . $attribs['id'] . '-multiple" class="ui-corner-all ui-state-default" style="display:none;">'; foreach ($labels as $label) { $tableTitles .= '<th>'; $tableTitles .= $label; $tableTitles .= '</th>'; } $tableTitles .= '</tr>'; $xhtmlElements .= '<div id="div-' . $attribs['id'] . '-multiple" style="float:left;clear:both;"> <table id="table-' . $attribs['id'] . '-multiple" boder="0" cellspacing="0" cellpadding="2"> ' . $tableTitles . ' </table> </div>'; } /** * Inicio da montagem de parâmetros do TSeeker */ $params['name'] = $searchId; if (isset($attribs['onFilter'])) { //$attribs['onFilter'] = str_replace("'", "\'", $attribs['onFilter']); $params['onFilter'] = new ZendT_JS_Command($attribs['onFilter']); } if (isset($attribs['onSearchValid'])) { $params['onSearchValid'] = new ZendT_JS_Command($attribs['onSearchValid']); } if (isset($attribs['onChange'])) { $params['onChange'] = new ZendT_JS_Command($attribs['onChange']); } if (isset($attribs['autoComplete']['onResult'])) { $params['autoComplete']['onResult'] = new ZendT_JS_Command($attribs['autoComplete']['onResult']); } if (isset($attribs['autoComplete']['onFormat'])) { $params['autoComplete']['onFormat'] = new ZendT_JS_Command($attribs['autoComplete']['onFormat']); } if (isset($attribs['autoComplete']['extraParams'])) { $params['autoComplete']['extraParams'] = $attribs['autoComplete']['extraParams']; } if (isset($attribs['onNotFound'])) { $params['onNotFound'] = new ZendT_JS_Command($attribs['onNotFound']); } if (isset($attribs['multiple'])) { $params['multiple'] = $attribs['multiple']; } if (isset($attribs['filterRefer'])) { $params['filterRefer'] = $attribs['filterRefer']; } $params['elements']['id'] = $attribs['propId']->getId(); $params['elements']['search'] = $searchId; $params['elements']['button'] = $attribs['button']->getId(); if (isset($attribs['propDisplay'])) { $params['elements']['display'] = $attribs['propDisplay']->getId(); } else { $params['elements']['display'] = ''; } $params['modal'] = $attribs['jQueryParams']['modal']; $params['modal']['type'] = strtoupper($params['modal']['type']); if (!in_array($params['modal']['type'], array('DIV', 'WINDOW'))) { $params['modal']['type'] = 'WINDOW'; } $params['url'] = $attribs['jQueryParams']['url']; if ($attribs['multiple']) { $params['data'] = $value; } /** * Cria os parâmetros para renderizar o seeker no jQuery */ $this->view->headLink()->appendStylesheet(ZendT_Url::getBaseDiretoryPublic() . '/scripts/jquery/extra/jquery.autocomplete.css'); $this->view->headScript()->appendFile(ZendT_Url::getBaseDiretoryPublic() . '/scripts/jquery/extra/jquery.autocomplete.js'); $this->view->headScript()->appendFile(ZendT_Url::getBaseDiretoryPublic() . '/scripts/jquery/widget/TAutocomplete.js'); $this->view->headScript()->appendFile(ZendT_Url::getBaseDiretoryPublic() . '/scripts/jquery/widget/TSeeker.js'); $params = ZendT_JS_Json::encode($params); $params = str_replace('{id}', $searchId, $params); $js = 'jQuery("#' . $searchId . '").TSeeker(' . $params . ');'; $this->jquery->addOnLoad($js); /** * Limpa a memória */ unset($attribs['button']); unset($attribs['propId']); unset($attribs['propSearch']); unset($attribs['propDisplay']); unset($attribs['onFilter']); unset($attribs['onChange']); unset($attribs['onNotFound']); unset($attribs['onResult']); unset($attribs['onSearchValid']); unset($attribs['filterRefer']); unset($attribs['where']); return '<div class="ui-form-group">' . $xhtmlElements . '</div>'; }
/** * * @param Zend_View_Interface $view * @return type */ public function render(Zend_View_Interface $view = null) { $element = new ZendT_Form_Element('clear_both'); $element->setDecorators(array(new ZendT_Form_Decorator_ClearBoth())); $this->addElement($element); if ($this->_enablejQueryValidate) { $onLoad = $this->getView()->placeholder('onLoad')->getValue(); $onLoad['jQueryFormValidate'] = "jQuery('#" . $this->getId() . "').validate({ignore:[]});"; $this->getView()->placeholder('onLoad')->set($onLoad); } if (count($this->_url) > 1) { $this->getView()->headScript()->appendFile(ZendT_Url::getBaseDiretoryPublic() . '/scripts/jquery/widget/TForm.js?' . $data); $baseUrl = ZendT_Url::getBaseUrl(); $url = array(); foreach ($this->_url as $key => $value) { $url['url'][$key] = $baseUrl . $value; } $jsonParam = ZendT_JS_Json::encode($url); $onLoad = $this->getView()->placeholder('onLoad')->getValue(); $onLoad['jQueryForm'] = "jQuery('#" . $this->getId() . "').TForm(" . $jsonParam . ");"; $this->getView()->placeholder('onLoad')->set($onLoad); } if ($this->_enableFocusFirstElement) { $onLoad = $this->getView()->placeholder('onLoad')->getValue(); $onLoad['jQueryFormFocus'] = "focusFirstElement('#" . $this->getId() . " input, #" . $this->getId() . " textare, #" . $this->getId() . " select');"; $this->getView()->placeholder('onLoad')->set($onLoad); } $enableTinyMCE = false; $elements = $this->getElements(); $tinyMCE = ''; foreach ($elements as $element) { if ($element instanceof ZendT_Form_Element_Textarea) { if ($element->isEditorHtml()) { $tinyMCE .= "tinyMCE.get('" . $element->getId() . "').save();"; $enableTinyMCE = true; } } } if ($enableTinyMCE) { $onLoad = $this->getView()->placeholder('onLoad')->getValue(); $onLoad['tinyMCE'] = "jQuery('#" . $this->getId() . "').submit(function(){" . $tinyMCE . "});"; $this->getView()->placeholder('onLoad')->set($onLoad); } return parent::render($view); }
/** * * @param ZendT_Grid $grid * @return string */ public function gridTree(ZendT_Grid $grid) { $this->view->headScript()->appendFile(ZendT_Url::getBaseDiretoryPublic() . '/scripts/jquery/widget/TGridTree.js?date=180113'); $firstColumn = ''; /** * Linha de Título */ $rowTitle = '<tr>'; $numCols = 0; foreach ($grid->getColModel()->getColumns() as $column) { $style = ''; if ($column->getHidden()) { $style = 'display:none;'; } elseif ($firstColumn == '') { $firstColumn = $column->getName(); $numCols++; } else { $numCols++; } $style .= 'text-align:' . $column->getAlign() . ';'; $class = 't-ui-border-trb'; if ($firstColumn == $column->getName()) { $class = 't-ui-border-trbl'; } $rowTitle .= '<th class="ui-state-default ' . $class . '" style="' . $style . '">'; $rowTitle .= $column->getHeaderTitle(); $rowTitle .= '</th>'; } $rowTitle .= '</tr>'; /** * Linhas do Detalhe */ $rows = ''; $stylesRow = $grid->getStyles(); foreach ($grid->getRows() as $index => $row) { $class = ''; $style = ''; if ($grid->getTreeGrid() == 'true') { if (trim($row['tree_parent']) != '') { $class .= 'parent-' . $this->_normalizeId($row['tree_parent']); $style .= 'display:none'; } } $rowId = $this->_normalizeId($row['id']); $rows .= '<tr id="' . $rowId . '" class="' . $class . '" style="' . $style . '">'; foreach ($grid->getColModel()->getColumns() as $column) { $options = $column->getOptions(); $key = $column->getName(); if (in_array($key, array('tree_child', 'tree_level'))) { continue; } $style = ''; $attr = ''; if ($key == $firstColumn) { $attr = 'level="' . $row['tree_level'] . '" child="' . $row['tree_child'] . '" '; } if ($column->getHidden()) { $style = 'display:none;'; } $style .= 'text-align:' . $column->getAlign() . ';'; $style .= 'min-width:' . $column->getWidth() . 'px;'; if (isset($stylesRow[$index][$key])) { foreach ($stylesRow[$index][$key] as $styleName => $styleValue) { $style .= $styleName . ':' . $styleValue . ';'; } } $class = 't-ui-border-rb'; if ($firstColumn == $column->getName()) { $class = 't-ui-border-rbl'; } $rows .= '<td ' . $attr . 'class="ui-widget-content ' . $key . ' ' . $class . '" style="' . $style . '">'; $rows .= $row[$key]; $rows .= '</td>'; } $rows .= '</tr>'; } /** * Botões de Navegação */ $buttonsToolbar = $grid->getObjToolbar()->getButtons(); if ($buttonsToolbar) { $toolbar = ''; foreach ($buttonsToolbar as $button) { if ($button) { foreach ($button as $oneButton) { $toolbar .= $oneButton->renderHtml(); } } } $toolbar = '<tr> <th colspan="' . $numCols . '" class="ui-state-default" style="border-bottom:0px;text-align:left;"> ' . $toolbar . ' </th> </tr>'; } /** * Parâmetros do jQuery para criar a árvore */ $params = array('columns' => array('group' => $firstColumn, 'parent' => 'tree_parent', 'level' => 'tree_level')); $params = ZendT_JS_Json::encode($params); $this->jquery->addOnLoad('jQuery("#' . $grid->getID() . '").TGridTree(' . $params . ');'); return '<table width="100%" class="ui-jqgrid-htable" cellspacing="0" cellpadding="3" border="0" id="' . $grid->getID() . '"> ' . $toolbar . ' ' . $rowTitle . ' ' . $rows . ' </table>'; }
/** * Cria o script JS para a execução dos tabs * * @return string */ public function createJS() { //$this->addHeadScriptFile(ZendT_Url::getBaseDiretoryPublic() . '/scripts/jquery/widget/TTabs.js'); if ($this->_disabledAll) { if (count($this->_tabs) > 2) { for ($i = 2; $i < count($this->_tabs); $i++) { $this->_options['disabled'][] = $i; } } else { unset($this->_options['disabled']); } } $options = array(); if (count($this->_options) > 0) { $options = $this->_options; } if (count($this->_tabs) > 0) { $options = array_merge($options, $this->_tabs); } $onSelect = $this->_onSelect; if ($onSelect instanceof ZendT_JS_Command) { $onSelect = 'var onSelect = ' . $onSelect->render() . '; onSelect(event, ui);'; } else { if ($onSelect) { $onSelect = new ZendT_JS_Command("function(event, ui){ return {$onSelect}(event, ui); }"); } } $options['onSelect'] = $onSelect; $js = "jQuery('#" . $this->getId() . "').TTabs("; $js .= ZendT_JS_Json::encode($options); $js .= ");\n"; /** * */ $jsTabs = array(); foreach ($this->_tabs as $index => $tabs) { if ($tabs['field'] != '' || $tabs['param'] != '') { $jsTabs[$index]['url'] = $tabs['url']; $jsTabs[$index]['field'] = $tabs['field']; $jsTabs[$index]['param'] = $tabs['param']; $jsTabs[$index]['value'] = $tabs['value']; $jsTabs[$index]['mapper'] = $tabs['mapper']; $jsTabs[$index]['operation'] = $tabs['operation']; } else { if ($tabs['url'] instanceof ZendT_JS_Command) { $jsTabs[$index]['url'] = $tabs['url']; $jsTabs[$index]['field'] = ''; $jsTabs[$index]['param'] = ''; } else { $jsTabs[$index]['field'] = ''; $jsTabs[$index]['param'] = ''; } } $jsTabs[$index]['iframe'] = $tabs['iframe']; } /** * */ /* if (count($jsTabs) > 0) { $js.= "$('#" . $this->getId() . "').bind('tabsselect', function(event, ui) { ".$onSelect." var tabsParam = {}; tabsParam = " . ZendT_JS_Json::encode($jsTabs) . "; if (tabsParam[ui.index].field){ var where = new TWhere('AND') where.addFilter({ field: tabsParam[ui.index].field, value: tabsParam[ui.index].value, operation: tabsParam[ui.index].operation, mapper: tabsParam[ui.index].mapper }); if (tabsParam[ui.index].iframe){ var urlGrid = tabsParam[ui.index].url + '?typeModal=IFRAME&filter_json=' + encodeURIComponent(where.toJson()); var objWindow = document.getElementById('" . $this->getId() . "_' + ui.index).contentWindow; objWindow.document.body.innerHTML = ''; objWindow.document.write('Carregando...'); document.getElementById('" . $this->getId() . "_' + ui.index).src = urlGrid; }else{ var urlGrid = tabsParam[ui.index].url + '?typeModal=AJAX&filter_json=' + encodeURIComponent(where.toJson()); $(ui.panel).html('" . $this->getLoadMsg() . "'); $('#" . $this->getId() . "').TTabs('changeUrl', urlGrid,ui.index); } }else if (tabsParam[ui.index].param){ var valueParam = ''; if (typeof tabsParam[ui.index].value == 'function'){ valueParam = tabsParam[ui.index].value(); }else{ valueParam = tabsParam[ui.index].value; } //$('#" . $this->getId() . "').TTabs('changeUrl', urlGrid,ui.index); if (tabsParam[ui.index].iframe){ var urlGrid = tabsParam[ui.index].url + '?typeModal=IFRAME&' + tabsParam[ui.index].param + '=' + encodeURIComponent(valueParam); var objWindow = document.getElementById('" . $this->getId() . "_' + ui.index).contentWindow; objWindow.document.body.innerHTML = ''; objWindow.document.write('Carregando...'); document.getElementById('" . $this->getId() . "_' + ui.index).src = urlGrid; }else{ var urlGrid = tabsParam[ui.index].url + '?typeModal=AJAX&' + tabsParam[ui.index].param + '=' + encodeURIComponent(valueParam); $(ui.panel).html('" . $this->getLoadMsg() . "'); $('#" . $this->getId() . "').TTabs('changeUrl', urlGrid,ui.index); } }else if (typeof tabsParam[ui.index].url == 'function'){ var urlGrid = tabsParam[ui.index].url(); //$('#" . $this->getId() . "').TTabs('changeUrl', urlGrid,ui.index); if (tabsParam[ui.index].iframe){ var objWindow = document.getElementById('" . $this->getId() . "_' + ui.index).contentWindow; objWindow.document.body.innerHTML = ''; objWindow.document.write('Carregando...'); document.getElementById('" . $this->getId() . "_' + ui.index).src = urlGrid; }else{ $(ui.panel).html('" . $this->getLoadMsg() . "'); $('#" . $this->getId() . "').TTabs('changeUrl', urlGrid,ui.index); } } });"; } */ /* if ($onSelect){ $js.= "$('#" . $this->getId() . "').bind('tabsload', function(event, ui) { ".$onSelect." });"; } */ return $js; }
function sql2json($value) { $_parse = new ZendT_Db_Adapter_ParseSQL(); $data = $_parse->toArray($value); return ZendT_JS_Json::encode($data); }