*/ $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"));
$fs->setFrame(true)->setTitle("XML Form")->setLabelAlign(PhpExt_Form_FormPanel::LABEL_ALIGN_RIGHT)->setLabelWidth(85)->setWidth(340)->setWaitMsgTarget(true); // configure how to read the XML Data $reader = new PhpExt_Data_XmlReader(); $reader->setRecord("contact")->setSuccess("@success"); $reader->addField(new PhpExt_Data_FieldConfigObject("first", "name/first")); // custom mapping $reader->addField(new PhpExt_Data_FieldConfigObject("last", "name/last")); $reader->addField(new PhpExt_Data_FieldConfigObject("company", "company")); $reader->addField(new PhpExt_Data_FieldConfigObject("email", "email")); $reader->addField(new PhpExt_Data_FieldConfigObject("state", "state")); $reader->addField(new PhpExt_Data_FieldConfigObject("dob", "dob", "date", "m/d/Y")); // custom data types $fs->setReader($reader); $fs->setErrorReader(new PhpExtUx_Form_XmlErrorReader()); $fset = new PhpExt_Form_FieldSet(); $fset->setTitle("Contact Information")->setAutoHeight(true)->setDefaultType("textfield")->setDefaults(new PhpExt_Config_ConfigObject(array("width" => 190)))->addItem(PhpExt_Form_TextField::createTextField("first", "First Name"))->addItem(PhpExt_Form_TextField::createTextField("last", "Last Name"))->addItem(PhpExt_Form_TextField::createTextField("company", "Company"))->addItem(PhpExt_Form_TextField::createTextField("email", "Email", null, PhpExt_Form_FormPanel::VTYPE_EMAIL)); $combo = PhpExt_Form_ComboBox::createComboBox("state", "State")->setValueField("abbr")->setDisplayField("state")->setTypeAhead(true)->setMode(PhpExt_Form_ComboBox::MODE_LOCAL)->setTriggerAction(PhpExt_Form_ComboBox::TRIGGER_ACTION_ALL)->setEmptyText("Select a state...")->setSelectOnFocus(true); $store = new PhpExt_Data_SimpleStore(); $store->addField("abbr"); $store->addField("state"); $store->setData(PhpExt_Javascript::variable("Ext.exampledata.states")); $combo->setStore($store); $fset->addItem($combo); $fset->addItem(PhpExt_Form_DateField::createDateField("dob", "Data of Birth")->setAllowBlank(false)); $fs->addItem($fset); $fs->addButton(PhpExt_Button::createTextButton("Load", new PhpExt_Handler(PhpExt_Javascript::stm("fs.getForm().load({url:'examples/form/xml-form.xml', waitMsg:'Loading',method: 'GET'})")))); $submitBtn = PhpExt_Button::createTextButton("Submit", new PhpExt_Handler(PhpExt_Javascript::stm("fs.getForm().submit({url:'examples/form/xml-errors.xml', waitMsg:'Saving Data...'})"))); $fs->addButton($submitBtn); //****************************** onReady echo PhpExt_Ext::onReady(PhpExt_Javascript::stm(PhpExt_QuickTips::init()), PhpExt_Javascript::assign("Ext.form.Field.prototype.msgTarget", PhpExt_Javascript::valueToJavascript(PhpExt_Form_FormPanel::MSG_TARGET_SIDE)), $fs->getJavascript(false, "fs"), PhpExt_Javascript::assignNew("submit", $submitBtn->getJavascript()), $fs->render("form-ct"));
$tabs2->addItem($columnPanel2); //- First column $firstColumn2 = new PhpExt_Panel(); // Use FormLayout to enable field labels and autoarrange fields on the panel $firstColumn2->setBorder(false)->setLayout(new PhpExt_Layout_FormLayout()); // Anchor the field to 95% of the panel by setting AnchorLayoutData (FormLayout extends AnchorLayout) $firstColumn2->addItem(PhpExt_Form_TextField::createTextField("first", "First Name"), new PhpExt_Layout_AnchorLayoutData("95%"))->addItem(PhpExt_Form_TextField::createTextField("company", "Company"), new PhpExt_Layout_AnchorLayoutData("95%")); // adds the panel as a 50% column using ColumnLayoutData $columnPanel2->addItem($firstColumn2, new PhpExt_Layout_ColumnLayoutData(0.5)); //- Second column $secondColumn2 = new PhpExt_Panel(); $secondColumn2->setBorder(false)->setLayout(new PhpExt_Layout_FormLayout())->addItem(PhpExt_Form_TextField::createTextField("last", "Last Name"), new PhpExt_Layout_AnchorLayoutData("95%"))->addItem(PhpExt_Form_TextField::createTextField("email", "Email")->setVType(PhpExt_Form_FormPanel::VTYPE_EMAIL), new PhpExt_Layout_AnchorLayoutData("95%")); $columnPanel2->addItem($secondColumn2, new PhpExt_Layout_ColumnLayoutData(0.5)); //- Tab Panel $tabPanel2 = new PhpExt_TabPanel(); $tabPanel2->setPlain(true)->setActiveTab(0)->setHeight(235)->setDefaults(new PhpExt_Config_ConfigObject(array("bodyStyle" => "padding:10px"))); $detailsTab2 = new PhpExt_Panel(); $detailsTab2->setTitle("Personal Details")->setLayout(new PhpExt_Layout_FormLayout())->setDefaults(new PhpExt_Config_ConfigObject(array("width" => 230)))->setDefaultType("textfield")->addItem(PhpExt_Form_TextField::createTextField("first", "First Name")->setAllowBlank(false)->setValue("Jack"))->addItem(PhpExt_Form_TextField::createTextField("company", "Company")->setValue("Slocum"))->addItem(PhpExt_Form_TextField::createTextField("last", "Last Name")->setValue("Ext JS"))->addItem(PhpExt_Form_TextField::createTextField("email", "Email")->setVType(PhpExt_Form_FormPanel::VTYPE_EMAIL)); $phonesTab2 = new PhpExt_Panel(); $phonesTab2->setTitle("Phone Numbers")->setLayout(new PhpExt_Layout_FormLayout())->setDefaults(new PhpExt_Config_ConfigObject(array("width" => 230)))->setDefaultType("textfield")->addItem(PhpExt_Form_TextField::createTextField("home", "Home")->setValue("(888) 555-1212"))->addItem(PhpExt_Form_TextField::createTextField("business", "Business"))->addItem(PhpExt_Form_TextField::createTextField("mobile", "Mobile"))->addItem(PhpExt_Form_TextField::createTextField("fax", "Fax")); $bioTab = new PhpExt_Panel(); $bioTab->setCssClass("x-plain")->setTitle("Biography")->setLayout(new PhpExt_Layout_FitLayout())->addItem(PhpExt_Form_HtmlEditor::createHtmlEditor("bio2", "Biography", "bio2")); $tabPanel2->addItem($detailsTab2); $tabPanel2->addItem($phonesTab2); $tabPanel2->addItem($bioTab); $tabs2->addItem($tabPanel2); $tabs2->addButton(PhpExt_Button::createTextButton("Save")); $tabs2->addButton(PhpExt_Button::createTextButton("Cancel")); //****************************** onReady echo PhpExt_Ext::onReady(PhpExt_QuickTips::init(), PhpExt_Javascript::assign("bd", "Ext.get('centercolumn')"), PhpExt_Javascript::stm("bd.createChild({tag: 'h2', html: 'Form 1 - Very Simple'})"), $simple->getJavascript(false, "simple"), $simple->render(PhpExt_Javascript::variable("Ext.get('centercolumn')")), PhpExt_Javascript::stm("bd.createChild({tag: 'h2', html: 'Form 2 - Adding fieldsets'})"), $fsf->getJavascript(false, "fsf"), $fsf->render(PhpExt_Javascript::variable("Ext.get('centercolumn')")), PhpExt_Javascript::stm("bd.createChild({tag: 'h2', html: 'Form 3 - A little more complex'})"), $top->getJavascript(false, "top"), $top->render(PhpExt_Javascript::variable("Ext.get('centercolumn')")), PhpExt_Javascript::stm("bd.createChild({tag: 'h2', html: 'Form 4 - Forms can be a TabPanel...'})"), $tabs->getJavascript(false, "tabs"), $tabs->render(PhpExt_Javascript::variable("Ext.get('centercolumn')")), PhpExt_Javascript::stm("bd.createChild({tag: 'h2', html: 'Form 5 - ... and forms can contain TabPanel(s)'})"), $tabs2->getJavascript(false, "tabs2"), $tabs2->render(PhpExt_Javascript::variable("Ext.get('centercolumn')")));