/** * Creates a javascript statement with a semicolon at the end. * @param string Javascript statement code * @return JavascriptStm */ public static function stm($statement) { if (PhpExt_Javascript::isJavascriptStm($statement)) { return PhpExt_Javascript::inlineStm($statement->output() . ";"); } return PhpExt_Javascript::inlineStm($statement . ";"); }
<?php set_include_path(get_include_path() . PATH_SEPARATOR . realpath('../../library')); include_once 'PhpExt/Javascript.php'; PhpExt_Javascript::sendContentType(); include_once 'PhpExt/Ext.php'; include_once 'PhpExt/Handler.php'; include_once 'PhpExt/Template.php'; include_once 'PhpExt/XTemplate.php'; include_once 'PhpExt/Panel.php'; include_once 'PhpExt/Toolbar/Toolbar.php'; $data = array('name' => 'Jack Slocum', 'company' => 'Ext JS, LLC', 'address' => '4 Red Bulls Drive', 'city' => 'Cleveland', 'state' => 'Ohio', 'zip' => '44102', 'kids' => array(array('name' => 'Sara Grace', 'age' => 3), array('name' => 'Zachary', 'age' => 2), array('name' => 'John James', 'age' => 0))); /* Example 1: Basic Template */ $t = new PhpExt_Template("<p>Name: {name}</p>", "<p>Company: {company}</p>", '<p>Location: {city}, {state}</p>'); $p = new PhpExt_Panel(); $p->setTitle('Basic Template')->setWidth('300')->setHtml('<p><i>Apply the template to see results here</i></p>'); $tb = $p->getTopToolbar(); $tb->addButton("apply", "Apply Template", null, new PhpExt_Handler(PhpExt_Javascript::stm($t->getJavascript(false, "tpl")), $t->overwrite(PhpExt_Javascript::variable("p.body"), PhpExt_Javascript::variable("data")))); $p->setRenderTo(PhpExt_Javascript::inlineStm("Ext.get('centercolumn')")); /** Example 2: XTemplate */ $t2 = new PhpExt_XTemplate('<p>Name: {name}</p>', '<p>Company: {company}</p>', '<p>Location: {city}, {state}</p>', '<p>Kids: ', '<tpl for="kids" if="name==\\\'Jack Slocum\\\'">', '<tpl if="age > 1"><p>{#}. {parent.name}\\\'s kid - {name}</p></tpl>', '</tpl></p>'); //$t2->VarName = "tpl2"; $p2 = new PhpExt_Panel(); $p2->setTitle('XTemplate')->setWidth('300')->setHtml('<p><i>Apply the template to see results here</i></p>'); $tb2 = $p2->getTopToolbar(); $tb2->addButton("apply", "Apply Template", null, new PhpExt_Handler(PhpExt_Javascript::stm($t2->getJavascript(false, "tpl2")), $t2->overwrite(PhpExt_Javascript::variable("p2.body"), PhpExt_Javascript::variable("data")))); $p2->setRenderTo(PhpExt_Javascript::variable("Ext.get('centercolumn')")); echo PhpExt_Ext::onReady(PhpExt_Javascript::stm("var data = " . PhpExt_Javascript::jsonEncode($data) . ";"), $p->getJavascript(false, "p"), $p2->getJavascript(false, "p2"));
/** * @return JavascriptStm */ public static function getMethodInvokeStm($instanceVarName, $methodSignature, $inline = false) { $params = array(); foreach ($methodSignature['params'] as $key => $value) { $params[$key] = PhpExt_Javascript::valueToJavascript($value); } if ($methodSignature['static']) { $js = isset($this) && isset($this->_extClassName) && $this->_extClassName != null ? $this->_extClassName : $instanceVarName; } else { $js = $instanceVarName; } $js .= "." . $methodSignature['methodName'] . "(" . implode(",", $params) . ")"; return $inline ? PhpExt_Javascript::inlineStm($js) : PhpExt_Javascript::stm($js); }
$if_leaf_html = PhpExt_Javascript::functionNoDef("if", $add_tab_invoke_html, array("n.leaf")); $add_tab_onclick = PhpExt_Javascript::functionDef(null, $if_leaf, array("n")); $add_tab_oncontextmenu = PhpExt_Javascript::functionDef(null, $if_leaf_html, array("n")); $output_add_tab_onclick = $get_tree_panel->on("click", $add_tab_onclick); $output_add_tab_oncontextmenu = $get_tree_panel->on("contextmenu", $add_tab_oncontextmenu); $output_add_tab_function = new PhpExt_JavascriptStm($add_tab_function); //-----------------------------------------------------------BARRA DE ESTADO-------------------------------------------------------------------------------------------- $function_win_open = PhpExt_Javascript::callfunction("window.open", array("'http://www.nutus.com.ar'")); $handler_abrir_pagina = PhpExt_Javascript::functionDef("", $function_win_open, array("e")); $function_win_open2 = PhpExt_Javascript::callfunction("window.open", array("'http://soporte.nutus.info'")); $handler_abrir_pagina2 = PhpExt_Javascript::functionDef("", $function_win_open2, array("e")); $barra_estado = new PhpExt_Toolbar_StatusBar(); $barra_estado->setId("status_bar"); $barra_estado->setDefaultText("Terminado"); $barra_estado->addButton("ayuda", "Ayuda on-line", null, $handler_abrir_pagina2); $barra_estado->addButton("Pagina", "© Nutus 2009", null, $handler_abrir_pagina); $status_bar = new PhpExt_Panel(); $status_bar->setBottomToolbar($barra_estado); //USO UN VIEWPORT YA QUE SE ADAPTA AL ANCHO DE LA PAGINA //creo uno nuevo y le agrego todos los items setando el area $contenedor = new PhpExt_Viewport(); $contenedor->setLayout(new PhpExt_Layout_BorderLayout()); $contenedor->addItem($menu_top, PhpExt_Layout_BorderLayoutData::createNorthRegion()); $contenedor->addItem($menu_acordion, PhpExt_Layout_BorderLayoutData::createWestRegion()); $contenedor->addItem($principal, PhpExt_Layout_BorderLayoutData::createCenterRegion()); $contenedor->addItem($status_bar, PhpExt_Layout_BorderLayoutData::createSouthRegion()); //FUNCTIONS DE USO GENERAL $format_money = "\t\nfunction FormatMoney(v,sign){\t\t\t\t\n v = (Math.round((v-0)*100))/100;\n v = (v == Math.floor(v)) ? v + '.00' : ((v*10 == Math.floor(v*10)) ? v + '0' : v);\n v = String(v); \n if(v.charAt(0) == '-'){\n return '-' + sign + v.substr(1).replace('.',',');\n }\n return sign + v.replace('.',',');\n}\n"; $unformat_money = "\nfunction unformatMoney(num) {\n\tvar value = num.replace(',','.');\t\t\n\treturn value.replace(/([^0-9\\.\\-])/g,'')*1;\t\n}\n"; echo PhpExt_Ext::OnReady(PhpExt_QuickTips::init(), $contenedor->getJavascript(false, "Contenedor"), $contenedor->render(PhpExt_Javascript::inlineStm("document.body")), $output_add_tab_function->output(), $output_add_tab_onclick, $output_add_tab_oncontextmenu, $unformat_money, $format_money);
include_once 'PhpExt/Handler.php'; include_once 'PhpExt/MessageBox.php'; include_once 'PhpExt/MessageBoxOptions.php'; include_once 'PhpExt/ProgressBarWaitConfig.php'; $mb1Element = PhpExt_Element::getById('mb1'); $mb1Handler = PhpExt_Javascript::functionDef(null, PhpExt_MessageBox::confirm("Confirm", "Are you sure you want to do that", PhpExt_Javascript::variable('showResult')), array("e")); $mb2Element = PhpExt_Element::getById('mb2'); $mb2Handler = PhpExt_Javascript::functionDef(null, PhpExt_MessageBox::prompt("Name", "Please enter your name:", PhpExt_Javascript::variable('showResultText')), array("e")); $mb3Element = PhpExt_Element::getById('mb3'); $mb3Options = PhpExt_MessageBoxOptions::createMsgOptions()->setTitle('Address')->setMsg('Please enter your address:')->setWidth(300)->setButtons(PhpExt_MessageBox::OKCANCEL())->setMultiline(true)->setFn(PhpExt_Javascript::variable('showResultText'))->setAnimEl('mb3'); $mb3Handler = PhpExt_Javascript::functionDef(null, PhpExt_MessageBox::show($mb3Options)); $mb4Element = PhpExt_Element::getById('mb4'); $mb4Options = PhpExt_MessageBoxOptions::createMsgOptions()->setTitle('Save Changes?')->setMsg('You are closing a tab that has unsaved changes. <br />Would you like to save your changes?')->setButtons(PhpExt_MessageBox::YESNOCANCEL())->setFn(PhpExt_Javascript::variable('showResult'))->setAnimEl('mb4')->setIcon(PhpExt_MessageBox::QUESTION()); $mb4Handler = PhpExt_Javascript::functionDef(null, PhpExt_MessageBox::show($mb4Options)); $mb6Element = PhpExt_Element::getById('mb6'); $mb6Options = PhpExt_MessageBoxOptions::createMsgOptions()->setTitle('Please wait')->setMsg('Loading items...')->setProgressText('Initializing...')->setWidth(300)->setProgress(true)->setClosable(false)->setAnimEl('mb6'); $mb6Hide = PhpExt_MessageBox::hide()->output(); $mb6Progress = PhpExt_MessageBox::updateProgress(PhpExt_Javascript::variable("i"), PhpExt_Javascript::inlineStm("Math.round(100*i)+'% completed'"))->output(); $mb6Handler = PhpExt_Javascript::functionDef(null, PhpExt_MessageBox::show($mb6Options)->output() . "\r\n\t\t// this hideous block creates the bogus progress\r\n var f = function(v){\r\n return function(){\r\n if(v == 12){\r\n " . $mb6Hide . ";\r\n Ext.example.msg('Done', 'Your fake items were loaded!');\r\n }else{\r\n var i = v/11;\r\n\t\t\t\t\t" . $mb6Progress . "; \r\n }\r\n };\r\n };\r\n for(var i = 1; i < 13; i++){\r\n setTimeout(f(i), i*500);\r\n }"); $mb7Element = PhpExt_Element::getById('mb7'); $mb7Options = PhpExt_MessageBoxOptions::createMsgOptions()->setMsg('Saving your data, please wait...')->setProgressText('Saving...')->setWait(true)->setWaitConfig(PhpExt_ProgressBarWaitConfig::createWaitConfig()->setInterval(200))->setIcon('ext-mb-download')->setAnimEl('mb7'); $mb7Handler = PhpExt_Javascript::functionDef(null, PhpExt_MessageBox::show($mb7Options)->output() . "\r\n\t\tsetTimeout(function(){\r\n //This simulates a long-running operation like a database save or XHR call.\r\n //In real code, this would be in a callback function.\r\n " . PhpExt_MessageBox::hide()->output() . ";\r\n Ext.example.msg('Done', 'Your fake data was saved!');\r\n }, 8000);"); $mb8Element = PhpExt_Element::getById('mb8'); $mb8Handler = PhpExt_Javascript::functionDef(null, PhpExt_MessageBox::alert("Status", "Changes saved successfully.", PhpExt_Javascript::variable('showResult'))); $comboValues = PhpExt_Javascript::stm("\r\n\t//Add these values dynamically so they aren't hard-coded in the html\r\n Ext.fly('info').dom.value = Ext.MessageBox.INFO;\r\n Ext.fly('question').dom.value = Ext.MessageBox.QUESTION;\r\n Ext.fly('warning').dom.value = Ext.MessageBox.WARNING;\r\n Ext.fly('error').dom.value = Ext.MessageBox.ERROR;\r\n"); $mb9Element = PhpExt_Element::getById('mb9'); $mb9Options = PhpExt_MessageBoxOptions::createMsgOptions()->setTitle('Icon Support')->setMsg('Here is a message with an icon!')->setButtons(PhpExt_MessageBox::OK())->setFn(PhpExt_Javascript::variable('showResult'))->setAnimEl('mb9')->setIcon(PhpExt_Javascript::variable("Ext.get('icons').dom.value")); $mb9Handler = PhpExt_Javascript::functionDef(null, PhpExt_MessageBox::show($mb9Options)); $showResult = PhpExt_Javascript::stm("function showResult(btn){\r\n Ext.example.msg('Button Click', 'You clicked the {0} button', btn);\r\n };"); $showResultText = PhpExt_Javascript::stm("function showResultText(btn, text){\r\n Ext.example.msg('Button Click', 'You clicked the {0} button and entered the text \"{1}\".', btn, text);\r\n };"); echo PhpExt_Ext::OnReady($mb1Element->on("click", $mb1Handler), $mb2Element->on("click", $mb2Handler), $mb3Element->on("click", $mb3Handler), $mb4Element->on("click", $mb4Handler), $mb6Element->on("click", $mb6Handler), $mb7Element->on("click", $mb7Handler), $mb8Element->on("click", $mb8Handler), $comboValues, $mb9Element->on("click", $mb9Handler), $showResult, $showResultText);
$store->setData($myData) */ $italicRenderer = PhpExt_Javascript::functionDef("italic", "return '<i>' + value + '</i>'", array("value")); $changeRenderer = PhpExt_Javascript::functionDef("change", "if(val > 0){\r\n return '<span style=\"color:green;\">' + val + '</span>';\r\n }else if(val < 0){\r\n return '<span style=\"color:red;\">' + val + '</span>';\r\n }\r\n return val;", array("val")); $pctChangeRenderer = PhpExt_Javascript::functionDef("pctChange", "if(val > 0){\r\n return '<span style=\"color:green;\">' + val + '%</span>';\r\n }else if(val < 0){\r\n return '<span style=\"color:red;\">' + val + '%</span>';\r\n }\r\n return val;", array("val")); // ColumnModel $colModel = new PhpExt_Grid_ColumnModel(); $colModel->addColumn(PhpExt_Grid_ColumnConfigObject::createColumn("Company", "company", "company", 160, null, null, true, false))->addColumn(PhpExt_Grid_ColumnConfigObject::createColumn("Price", "price", null, 75, null, PhpExt_Javascript::variable("Ext.util.Format.usMoney"), null, true))->addColumn(PhpExt_Grid_ColumnConfigObject::createColumn("Change", "change", null, 75, null, PhpExt_Javascript::variable('change'), null, true))->addColumn(PhpExt_Grid_ColumnConfigObject::createColumn("% Change", "pctChange", null, 75, null, PhpExt_Javascript::variable('pctChange'), null, true))->addColumn(PhpExt_Grid_ColumnConfigObject::createColumn("Last Updated", "lastChange", null, 75, null, PhpExt_Javascript::variable("Ext.util.Format.dateRenderer('m/d/Y')"), null, true)); // Form Panel $gridForm = new PhpExt_Form_FormPanel("company-form"); $gridForm->setFrame(true)->setLabelAlign(PhpExt_Form_FormPanel::LABEL_ALIGN_LEFT)->setTitle("Company Data")->setBodyStyle("padding: 5px;")->setWidth(750)->setLayout(new PhpExt_Layout_ColumnLayout()); // Setup Grid $leftPanel = new PhpExt_Panel(); $leftPanel->setLayout(new PhpExt_Layout_FitLayout()); $selModel = new PhpExt_Grid_RowSelectionModel(); $selModel->setSingleSelect(true)->attachListener("rowselect", new PhpExt_Listener(PhpExt_Javascript::functionDef(null, "Ext.getCmp(\"company-form\").getForm().loadRecord(rec);", array("sm", "row", "rec")))); $grid = new PhpExt_Grid_GridPanel(); $grid->setStore($store)->setColumnModel($colModel)->setSelectionModel($selModel)->setAutoExpandColumn("company")->setHeight(350)->setTitle("Company Data")->setBorder(true)->attachListener("render", new PhpExt_Listener(PhpExt_Javascript::functionDef(null, "g.getSelectionModel().selectRow(0);", array("g")), null, 10)); $leftPanel->addItem($grid); $gridForm->addItem($leftPanel, new PhpExt_Layout_ColumnLayoutData(0.6)); // Setup Fields $rightPanel = new PhpExt_Form_FieldSet(); $rightPanel->setLabelWidth(90)->setTitle("Company Details")->setDefaults(new PhpExt_Config_ConfigObject(array("width" => 140)))->setDefaultType("textfield")->setAutoHeight(true)->setBodyStyle(PhpExt_Javascript::inlineStm("Ext.isIE ? 'padding:0 0 5px 15px;' : 'padding:10px 15px;'"))->setBorder(false)->setCssStyle(new PhpExt_Config_ConfigObject(array("margin-left" => "10px", "margin-right" => PhpExt_Javascript::inlineStm('Ext.isIE6 ? (Ext.isStrict ? "-10px" : "-13px") : "0"')))); $rightPanel->addItem(PhpExt_Form_TextField::createTextField("company", "Name")); $rightPanel->addItem(PhpExt_Form_TextField::createTextField("price", "Price")); $rightPanel->addItem(PhpExt_Form_TextField::createTextField("pctChange", "% Change")); $rightPanel->addItem(PhpExt_Form_TextField::createTextField("lastChange", "Last Updated")); $gridForm->addItem($rightPanel, new PhpExt_Layout_ColumnLayoutData(0.4)); $gridForm->setRenderTo(PhpExt_Javascript::variable("Ext.get('centercolumn')")); //****************************** onReady echo PhpExt_Ext::onReady(PhpExt_Javascript::stm(PhpExt_QuickTips::init()), PhpExt_Javascript::assign("data", PhpExt_Javascript::valueToJavascript($myData)), $store->getJavascript(false, "ds"), $italicRenderer, $changeRenderer, $pctChangeRenderer, $colModel->getJavascript(false, "colModel"), $gridForm->getJavascript(false, "gridForm"));
// ColumnModel $txtCommon = PhpExt_Form_TextField::createTextField('txtCommon')->setAllowBlank(false); $cmbLight = PhpExt_Form_ComboBox::createComboBox("cmbLight")->setTypeAhead(true)->setTriggerAction(PhpExt_Form_ComboBox::TRIGGER_ACTION_ALL)->setTransform("light")->setLazyRender(true)->setListCssClass('x-combo-list-small'); $txtPrice = PhpExt_Form_NumberField::createNumberField("txtPrice")->setAllowBlank(false)->setAllowNegative(false)->setMaxValue(100000); $dtAvailable = PhpExt_Form_DateField::createDateField("dtAvaliable")->setFormat("m/d/y")->setMinValue("01/01/06")->setDisabledDays(array(0, 6))->setDisabledDaysText("Plants are not available on the weekends"); $colModel = new PhpExt_Grid_ColumnModel(); $colModel->addColumn(PhpExt_Grid_ColumnConfigObject::createColumn("Common Name", "common", "common", 220)->setEditor($txtCommon))->addColumn(PhpExt_Grid_ColumnConfigObject::createColumn("Light", "light", null, 130)->setEditor($cmbLight))->addColumn(PhpExt_Grid_ColumnConfigObject::createColumn("Price", "price", "price", 70, PhpExt_Ext::HALIGN_RIGHT, "usMoney")->setEditor($txtPrice))->addColumn(PhpExt_Grid_ColumnConfigObject::createColumn("Avaliable", "availDate", "availDate", 95, null, PhpExt_Javascript::variable('formatDate'))->setEditor($dtAvailable))->addColumn($checkColumn); // this could be inline, but we want to define the Plant record // type so we can add records dynamically $fields = new PhpExt_Data_FieldConfigObjectCollection(); $fields->add(new PhpExt_Data_FieldConfigObject("common", null, PhpExt_Data_FieldConfigObject::TYPE_STRING)); $fields->add(new PhpExt_Data_FieldConfigObject("botanical", null, PhpExt_Data_FieldConfigObject::TYPE_STRING)); $fields->add(new PhpExt_Data_FieldConfigObject("light")); $fields->add(new PhpExt_Data_FieldConfigObject("price", null, PhpExt_Data_FieldConfigObject::TYPE_FLOAT)); $fields->add(new PhpExt_Data_FieldConfigObject("availDate", "availability", PhpExt_Data_FieldConfigObject::TYPE_DATE, "m/d/Y")); $fields->add(new PhpExt_Data_FieldConfigObject("indoor", null, PhpExt_Data_FieldConfigObject::TYPE_BOOLEAN)); $plant = PhpExt_Data_Record::create($fields); // Reader $reader = new PhpExt_Data_XmlReader(); $reader->setRecord("plant"); $reader->setRecordType("Plant"); // Store $store = new PhpExt_Data_Store(); $store->setUrl("examples/grid/plants.xml")->setReader($reader)->setSortInfo(new PhpExt_Data_SortInfoConfigObject("common")); // Grid $grid = new PhpExt_Grid_EditorGridPanel(); $grid->setClicksToEdit(1)->setStore($store)->setColumnModel($colModel)->setAutoExpandColumn("common")->setFrame(true)->setHeight(300)->setWidth(600)->setTitle("Edit Plants?")->setRenderTo("editor-grid"); $grid->getPlugins()->add($checkColumn); $grid->getTopToolbar()->addButton("add", "Add Plant", null, new PhpExt_Handler(PhpExt_Javascript::inlineStm("var p = new Plant({\r\n common: 'New Plant 1',\r\n light: 'Mostly Shade',\r\n price: 0,\r\n availDate: (new Date()).clearTime(),\r\n indoor: false\r\n });\r\n grid.stopEditing();\r\n store.insert(0, p);\r\n grid.startEditing(0, 0);"))); // Ext.OnReady ----------------------- echo PhpExt_Ext::onReady(PhpExt_QuickTips::init(), $formatDate, $checkColumn->getJavascript(false, "checkColumn"), $colModel->getJavascript(false, "cm"), PhpExt_Javascript::assignNew("Plant", $plant), $store->getJavascript(false, "store"), $grid->getJavascript(false, "grid"), $store->load());