public function formManager() { $this->data->query = Manager::getAppURL('fnbr20', 'annotation/layer/gridData'); $this->data->action = "@fnbr20/annotation/layer/save|formManager"; $fnbr20Layers = Manager::getSession()->fnbr20Layers; $this->data->layersToShow = \Maestro\Services\MJSON::encode($fnbr20Layers ?: []); $this->render(); }
public function getManager($control) { $value = ""; $data = $control->property->manager; if (count($data)) { $value = substr(MJSON::parse($data), 1, -1); $value = "data-manager=\"{$value}\" "; } return $value; }
public function generate() { if ($this->property->actionUpdate) { $this->addTool(_M("Save"), $this->property->actionUpdate, "icon-save"); } if ($this->property->actionDelete) { $this->addTool(_M("Delete"), $this->property->actionDelete, "icon-remove"); } if ($this->property->actionInsert) { $this->addTool(_M("Insert"), $this->property->actionDelete, "icon-add"); } if ($this->property->actionSelect) { $this->property->checkbox = true; } foreach ($this->property->columns as $column) { $column->style->width = $column->style->width ?: '0'; $column->field = \Manager::getOptions('fetchStyle') == \FETCH_NUM ? strtoupper($column->field) : $column->field; } if ($this->property->checkbox) { $column = new MDatagridColumn(); $column->field = $this->id . 'Check'; $column->type = "check"; array_unshift($this->property->columns, $column); } $custom = new \StdClass(); $events = new \StdClass(); foreach ($this->options as $option => $value) { if (substr($option, 0, 2) == 'on') { $events->{$option} = (object) $value; } else { $custom->{$option} = $value; } } $this->generateData(); //$this->generateJsData(); if ($this->property->url) { $custom->url = $this->property->url; } if ($this->property->singleSelect) { $custom->singleSelect = $this->property->singleSelect; } if ($this->property->pageLength) { $custom->pagination = true; $custom->pageSize = $this->property->pageLength; $custom->pageList = array(5, 10, 15, 20, 30, 50); } else { $custom->pagination = false; } if ($this->property->idField != '') { if (preg_match('/^[0-9]/', $this->property->idField)) { $this->property->idField = 'F' . $this->property->idField; } $custom->idField = \Manager::getOptions('fetchStyle') == \FETCH_NUM ? strtoupper($this->property->idField) : $this->property->idField; } $toolbar = ''; if ($this->property->toolbar) { $custom->toolbar = "#{$this->property->toolbar->id}"; $toolbar = $this->painter->mdiv($this->property->toolbar); } $custom->border = isset($this->style->border) ? $this->style->border : true; $fields = array(); foreach ($this->property->columns as $column) { $field = new StdClass(); $field->field = $column->field; $field->title = $column->title; $field->hidden = $column->visible === false; $field->idGrid = $this->id; if ($column->action) { $field->action = $column->action; } if ($column->style->width) { $field->width = $column->style->width; } if ($column->align) { $field->align = $column->align; } if ($column->align) { $field->halign = $column->halign; } $field->type = $column->type ?: 'label'; if ($column->property->options) { $field->options = $column->property->options; } if ($column->render) { $field->render = $column->render; } if ($column->stylizer) { $field->stylizer = $column->stylizer; } if ($column->index) { $field->field = 'F' . $column->index; } if ($column->type == "control") { $controls = $column->getControls(); $firstControl = current($controls); $htmlControl = MJSON::encode($firstControl->generate()); $field->idControl = $firstControl->id; $this->page->addJsCode("\$('#{$this->id}').data('{$field->idControl}', {$htmlControl});\n"); } if ($column->type == "check") { $field->checkbox = true; } if ($column->type == "icon") { $field->icon = $column->icon; $field->alt = $column->alt; if ($column->field == '') { $field->field = substr(uniqid(), -6); } } $fields[] = $field; } $paramJson = MJSON::encode((object) ['custom' => $custom, 'columns' => $fields]); $eventJson = MJSON::encode((object) ['events' => $events]); $this->page->onLoad("theme.datagrid('{$this->property->id}','{$paramJson}', {$eventJson}, '{$this->property->data}');"); $this->property->idHidden = $this->property->id . '_data'; $idField = $this->property->idField; if ($idField != '') { $this->property->manager['idField'] = $idField; } $attributes = $this->painter->getAttributes($this); if ($this->property->head != '') { $thead = <<<EOT <thead> <tr> {$this->property->head} </tr> </thead> EOT; } $grid = <<<EOT <input type="hidden" id="{$this->property->idHidden}" name="{$this->property->idHidden}" value=""/> <table {$attributes}> {$thead} </table> EOT; if (!$this->form instanceof \MForm) { // Todos os grids precisam estar dentro de um form $formId = $baseId . '_form'; $grid = <<<EOT <form id="{$formId}" name="{$formId}" method="POST"> {$grid} </form> EOT; $this->property->form->id = $formId; } $this->result = $grid . $toolbar; return $this->result; }
public static function mprompt($control) { $promptType = ['information' => 'info', 'error' => 'error', 'question' => 'question', 'confirmation' => 'confirm', 'warning' => 'warning']; $dataJson = MJSON::encode((object) ['type' => $promptType[$control->property->type], 'title' => ucFirst(_M($control->property->type)), 'msg' => $control->property->msg]); $dataJson = addslashes($dataJson); //$control->property->id = 'mprompt'; $action1 = Action::parseAction(addslashes($control->property->action1)); $action2 = Action::parseAction(addslashes($control->property->action2)); self::$page->addJsCode("var {$control->property->id} = theme.prompt('{$control->property->id}','{$dataJson}',\"{$action1}\",\"{$action2}\");"); $show = $control->property->show === false ? false : true; if ($show) { self::$page->onLoad("{$control->property->id}.show();"); } }
private function getScripts() { if (count($this->events) > 0) { $events = MJSON::encode($this->events); $this->addOnload("manager.registerEvents(" . $events . ");"); } $scripts = new \StdClass(); foreach ($this->scripts as $key => $url) { $scripts->scripts .= "\n manager.loader.load('{$url}');"; } foreach ($this->jsCode as $key => $code) { $scripts->code .= "\n {$code}"; } foreach ($this->onload as $key => $code) { $scripts->onload .= "\n {$code}"; } $onsubmit = ''; foreach ($this->onsubmit as $idForm => $list) { $onsubmit .= "manager.onSubmit[\"{$idForm}\"] = function() { \n"; $onsubmit .= " var result = "; $onsubmit .= implode(" && ", $list) . ";\n"; $onsubmit .= " return result;\n};\n"; } $scripts->onsubmit = $onsubmit; /* $submit = ''; foreach ($this->submit as $idForm => $list) { $submit .= "manager.submit[\"{$idForm}\"] = function(element, url, idForm) { \n"; $submit .= implode(" && ", $list) . ";\n"; $submit .= "\n};\n"; } $scripts->submit = $submit; */ return $scripts; }
/** * Método auxiliar para montagem de grids de dados. * Retorna objeto JSON relativo a um criteria ou um array de dados. Os atributos "page" (número da página, 0-based) * e "rows" (número de linhas a serem retornadas) devem estar devidos em $this->data. * @param basecriteria|array $source Fonte de dados. * @param boolean $rowsOnly Se o JSON deve conter apenas os dados das linhas ou se deve conter também o total. * @param integer total * @return JSON object */ public function gridDataAsJSON($source, $rowsOnly = false, $total = 0) { $data = Manager::getData(); $result = (object) ['rows' => array(), 'total' => 0]; if ($source instanceof \Maestro\Persistence\Criteria\BaseCriteria) { $criteria = $source; $result->total = $criteria->asQuery()->count(); if ($data->page > 0) { $criteria->range($data->page, $data->rows); } $source = $criteria->asQuery(); } if ($source instanceof \Maestro\Database\MQuery) { $result->rows = $source->asObjectArray(); } elseif (is_array($source)) { $rows = array(); foreach ($source as $row) { $r = new \StdClass(); foreach ($row as $c => $col) { $field = is_numeric($c) ? 'F' . $c : $c; $r->{$field} = "{$col}"; } $rows[] = $r; } $result->rows = $rows; $result->total = $total != 0 ? $total : count($rows); } if ($rowsOnly) { return \Maestro\Services\MJSON::encode($result->rows); } else { return \Maestro\Services\MJSON::encode($result); } }
/** * array-walking static public for use in generating JSON-formatted name-value pairs * * @param string $name name of key to use * @param mixed $value reference to an array element to be encoded * * @return string JSON-formatted name-value pair, like '"name":value' * @access private */ public static function name_value($name, $value) { $encoded_value = self::_encode($value); if (MJSON::isError($encoded_value)) { return $encoded_value; } if (self::$jsObject) { return strval($name) . ':' . $encoded_value; } else { return self::_encode(strval($name)) . ':' . $encoded_value; } }
public static function toJSON($node) { $returnValue = ''; $JSON_node = new \stdClass(); // handle subnodes foreach ($node->composites as $composite) { if (!is_array($JSON_node->{$composite->nodeName})) { $JSON_node->{$composite->nodeName} = array(); } $JSON_node->{$composite->nodeName}[] = $composite->nodes; } if ($id = $node->getId()) { $JSON_node->id = $id; } if ($type = $node->getType()) { $JSON_node->type = $type; } if ($data = $node->getData()) { $JSON_node->data = $data; } $returnValue = \Maestro\Services\MJSON::encode($JSON_node); return $returnValue; }