コード例 #1
0
 protected function Form_Create()
 {
     // Define the DataGrid
     $this->tblPersons = new QHtmlTable($this);
     $this->tblPersons->CssClass = 'simple_table';
     $this->tblPersons->RowCssClass = 'odd_row';
     $this->tblPersons->AlternateRowCssClass = 'even_row';
     $this->tblPersons->HeaderRowCssClass = 'header_row';
     // Define Columns
     // This demonstrates how to first create a column, and then add it to the table
     $objColumn = new QHtmlTableCallableColumn('Full Name', [$this, 'getFullName']);
     $this->tblPersons->AddColumn($objColumn);
     // The second column demonstrates using a property name for fetching the data
     // This also demonstrates how to create a column and add it to the table all at once, using the CreatePropertyColumn shortcut
     $this->tblPersons->CreatePropertyColumn('First Name', 'FirstName');
     // The second column demonstrates using a node column for fetching the data
     $this->tblPersons->CreateNodeColumn('Last Name', QQN::Person()->LastName);
     // Specify the local Method which will actually bind the data source to the datagrid.
     // In order to not over-bloat the form state, the datagrid will use the data source only when rendering itself,
     // and then it will proceed to remove the data source from memory.  Because of this, you will need to define
     // a "data binding" method which will set the datagrid's data source.  You specify the name of the method
     // here.  The framework will be responsible for calling your data binding method whenever the datagrid wants
     // to render itself.
     $this->tblPersons->SetDataBinder('tblPersons_Bind');
     $this->tblReport = new QHtmlTable($this);
     $this->tblReport->CssClass = 'simple_table';
     $this->tblReport->RowCssClass = 'odd_row';
     $this->tblReport->AlternateRowCssClass = 'even_row';
     $this->tblReport->HeaderRowCssClass = 'header_row';
     // "named" index columns
     $this->tblReport->CreateIndexedColumn("Year", 0);
     $this->tblReport->CreateIndexedColumn("Model", 1);
     // "unnamed" index columns
     $this->tblReport->CreateIndexedColumn();
     $this->tblReport->CreateIndexedColumn();
     // index columns for associative arrays
     $this->tblReport->CreateIndexedColumn("Count", "#count");
     $this->tblReport->SetDataBinder('tblReport_Bind');
     $this->tblComplex = new QHtmlTable($this);
     $this->tblComplex->CssClass = 'simple_table';
     $this->tblComplex->RowCssClass = 'odd_row';
     $this->tblComplex->AlternateRowCssClass = 'even_row';
     $this->tblComplex->HeaderRowCssClass = 'header_row';
     // "named" index columns
     $col = $this->tblComplex->AddColumn(new ComplexColumn("", "Name"));
     $col->RenderAsHeader = true;
     $this->tblComplex->AddColumn(new ComplexColumn("2000", 1));
     $this->tblComplex->AddColumn(new ComplexColumn("2001", 2));
     $this->tblComplex->AddColumn(new ComplexColumn("2002", 3));
     $this->tblComplex->HeaderRowCount = 2;
     $this->tblComplex->SetDataBinder('tblComplex_Bind');
 }
コード例 #2
0
 /**
  * Recreate the tabs in the dialog
  */
 protected function SetupTabs()
 {
     $strClassNames = $this->CreateClassNameArray();
     $this->tabs->RemoveChildControls(true);
     $this->categories = array();
     $this->dtgGeneralOptions = new QHtmlTable($this->tabs, 'definitionTab');
     $this->dtgGeneralOptions->ShowHeader = false;
     $this->dtgGeneralOptions->Name = "General";
     $this->dtgGeneralOptions->CreatePropertyColumn('Attribute', 'Name');
     $col = $this->dtgGeneralOptions->AddColumn(new QHtmlTableCallableColumn('Attribute', array($this, 'dtg_ValueRender'), $this->dtgGeneralOptions));
     $col->HtmlEntities = false;
     $this->dtgGeneralOptions->SetDataBinder('dtgGeneralOptions_Bind', $this);
     /**
      * The following default options are somewhat matched to the default list and edit templates. A more robust
      * implementation would get the options from the templates, or what the templates generate, so that the templates
      * decide what to put there. If someone wants to radically change the templates, but still have them use this dialog
      * to edit the options, then would be the time to change the code below.
      */
     if ($this->objCurrentControl->LinkedNode->_ParentNode) {
         // Specify general options for a database column
         $this->generalOptions = array(new QModelConnectorParam(QModelConnectorParam::GeneralCategory, 'ControlClass', 'Override of the PHP type for the control. If you change this, save the dialog and reopen to reload the tabs to show the control specific options.', QModelConnectorParam::SelectionList, $strClassNames), new QModelConnectorParam(QModelConnectorParam::GeneralCategory, 'FormGen', 'Whether or not to generate this object, just a label for the object, just the control, or both the control and label', QModelConnectorParam::SelectionList, array(QFormGen::Both => 'Both', QFormGen::None => 'None', QFormGen::ControlOnly => 'Control', QFormGen::LabelOnly => 'Label')), new QModelConnectorParam(QModelConnectorParam::GeneralCategory, 'Name', 'Control\'s Name', QType::String), new QModelConnectorParam(QModelConnectorParam::GeneralCategory, 'NoColumn', 'True to prevent a column in the lister from being generated.', QType::Boolean));
     } else {
         // Specify general options for a database table, meaning an object that is listing the content of a whole table.
         // These would be options at a higher level than the control itself, and would modify how the control is used in a form.
         $this->generalOptions = array(new QModelConnectorParam(QModelConnectorParam::GeneralCategory, 'ControlClass', 'Override of the PHP type for the control. If you change this, save the dialog and reopen to reload the tabs to show the control specific options.', QModelConnectorParam::SelectionList, $strClassNames), new QModelConnectorParam(QModelConnectorParam::GeneralCategory, 'Name', 'The Control\'s Name. Generally leave this blank, or use a plural name.', QType::String), new QModelConnectorParam(QModelConnectorParam::GeneralCategory, 'ItemName', 'The public name of an item in the list. Its used by the title of the edit form, for example. Defaults to the name of the table in the database.', QType::String), new QModelConnectorParam(QModelConnectorParam::GeneralCategory, 'CreateFilter', 'Whether to generate a separate control to filter the data. If the data list control does its own filtering, set this to false. Default is true.', QType::Boolean), new QModelConnectorParam(QModelConnectorParam::GeneralCategory, 'EditMode', 'How to edit an item. 1) Options are: to go to a separate form, 2) popup a dialog, or 3) popup a dialog only if not on a mobile device since mobile devices struggle with showing dialogs that are bigger than the screen.', QModelConnectorParam::SelectionList, array('form' => 'Edit with a QForm', 'dialog' => 'Edit with a QDialog', 'both' => 'Edit with a form on mobile devices, and a dialog on desktops.')));
     }
     // load values from settings file
     foreach ($this->generalOptions as $objParam) {
         $objControl = $objParam->GetControl($this->dtgGeneralOptions);
         // get a control that will edit this option
         $strName = $objControl->Name;
         if (isset($this->params[$strName])) {
             $objControl->Value = $this->params[$strName];
             if ($strName == 'ControlClass') {
                 $strControlClass = $this->params[$strName];
             }
         } else {
             $objControl->Value = null;
         }
     }
     if (!isset($strControlClass)) {
         $strControlClass = get_class($this->objCurrentControl);
     }
     $params = $strControlClass::GetModelConnectorParams();
     // gather categories
     foreach ($params as $param) {
         $this->categories[$param->Category][] = $param;
     }
     // Add any additional general items to the general tab
     if (isset($this->categories[QModelConnectorParam::GeneralCategory])) {
         // load values from settings file
         foreach ($this->categories[QModelConnectorParam::GeneralCategory] as $objParam) {
             $objControl = $objParam->GetControl($this->dtgGeneralOptions);
             // get a control that will edit this option
             $strName = $objControl->Name;
             if (isset($this->params[$strName])) {
                 $objControl->Value = $this->params[$strName];
             } else {
                 $objControl->Value = null;
             }
             $this->generalOptions[] = $objParam;
         }
         unset($this->categories[QModelConnectorParam::GeneralCategory]);
     }
     foreach ($this->categories as $tabName => $params) {
         $panel = new QPanel($this->tabs);
         $panel->SetCustomStyle('overflow-y', 'scroll');
         $panel->SetCustomStyle('max-height', '200');
         $panel->AutoRenderChildren = true;
         $panel->Name = $tabName;
         $dtg = new QHtmlTable($panel);
         $dtg->ShowHeader = false;
         $dtg->CreatePropertyColumn('Attribute', 'Name');
         $col = $dtg->AddColumn(new QHtmlTableCallableColumn('Attribute', array($this, 'dtg_ValueRender'), $dtg));
         $col->HtmlEntities = false;
         $dtg->SetDataBinder('dtgControlBind', $this);
         $dtg->Name = $tabName;
         // holder for category
         $this->datagrids[$tabName] = $dtg;
         // load values from settings file
         foreach ($params as $objParam) {
             $objControl = $objParam->GetControl($this->datagrids[$tabName]);
             if ($objControl) {
                 $strName = $objControl->Name;
                 if (isset($this->params['Overrides'][$strName])) {
                     $objControl->Value = $this->params['Overrides'][$strName];
                 } else {
                     $objControl->Value = null;
                 }
             }
         }
     }
 }