public function enableSelectFilter($field, $data) { $id = $this->id . '-filter-' . $field; $value = $this->determineFilterValue($field); $this->components['filter_select'] = \Lucid\html\html::select(null, $value, $data, "lucid.html.dataTable.filter(this,false);")->id($id)->size('sm')->style('width:auto;'); $this->filters[$field] = ['field' => $field, 'operator' => 'equals', 'value' => $value]; return $this; }
public function edit(int $address_id) { # By default, require that the user be logged in to access the edit form. If you want additional # permissions, use the lucid::$app->$security->requirePermission() function. #lucid::$app->permission()->requireLogin(); # lucid::$app->$security->requirePermission('addresses-select'); # Set the title tag for the page. Optionally, you can also set the description or keywords meta tag # by calling lucid::$app->$response->description() or lucid::$app->$response->keywords() lucid::$app->response()->title(lucid::$app->i18n()->translate('branding:app_name') . ' - Addresses'); # Render the navigation controller. lucid::$app->factory()->view('navigation')->render('addresses.view.table', 'addresses.view.edit'); # Load the model. If $address_id == 0, then the model's ->create method will be called. $data = $this->controller()->getOne($address_id); # the ->notFound method will throw an error if the first parameter === false, which will be the case # if the model function is passed an ID that is not zero, but is not able to retrieve a row for that ID #lucid::$app->$error->notFound($data, '#body'); # Based on whether or not the primary key for the model == 0, the header message will either be the dictionary # key form:edit_new or form::edit_existing. $headerMsg = lucid::$app->i18n()->translate('form:edit_' . ($data->address_id == 0 ? 'new' : 'existing'), ['type' => 'addresses', 'name' => $data->name]); # Construct the form and retrieve the ruleset for the controller. You can have multiple functions in your # controller if you want to have that controller accept submissions from different forms with different numbers # of fields, but the auto-generated ruleset-returning function is simply called ->ruleset(). The ->send() # method of the ruleset object packages up the rules into json, and sends them to the client so that they can be # used clientside when the form submits. $form = html::form('addresses-edit', '#!addresses.controller.save'); $this->ruleset('edit')->send($form->name); $org_id_options = lucid::$app->factory()->model('organizations')->select('org_id', 'value')->select('name', 'label')->order_by_asc('name')->find_array(); $org_id_options = array_merge([0, ''], $org_id_options); $region_id_options = lucid::$app->factory()->model('regions')->select('region_id', 'value')->select('country_id', 'label')->order_by_asc('country_id')->find_array(); $region_id_options = array_merge([0, ''], $region_id_options); $country_id_options = lucid::$app->factory()->model('countries')->select('country_id', 'value')->select('alpha_3', 'label')->order_by_asc('alpha_3')->find_array(); $country_id_options = array_merge([0, ''], $country_id_options); # create the main structure for the form $card = html::card(); $card->header()->add($headerMsg); $card->block()->add([html::formGroup(lucid::$app->i18n()->translate('model:addresses:org_id'), html::select('org_id', $data->org_id, $org_id_options)), html::formGroup(lucid::$app->i18n()->translate('model:addresses:name'), html::input('text', 'name', $data->name)), html::formGroup(lucid::$app->i18n()->translate('model:addresses:street_1'), html::input('text', 'street_1', $data->street_1)), html::formGroup(lucid::$app->i18n()->translate('model:addresses:street_2'), html::input('text', 'street_2', $data->street_2)), html::formGroup(lucid::$app->i18n()->translate('model:addresses:city'), html::input('text', 'city', $data->city)), html::formGroup(lucid::$app->i18n()->translate('model:addresses:region_id'), html::select('region_id', $data->region_id, $region_id_options)), html::formGroup(lucid::$app->i18n()->translate('model:addresses:postal_code'), html::input('text', 'postal_code', $data->postal_code)), html::formGroup(lucid::$app->i18n()->translate('model:addresses:country_id'), html::select('country_id', $data->country_id, $country_id_options)), html::formGroup(lucid::$app->i18n()->translate('model:addresses:phone_number_1'), html::input('text', 'phone_number_1', $data->phone_number_1)), html::formGroup(lucid::$app->i18n()->translate('model:addresses:phone_number_2'), html::input('text', 'phone_number_2', $data->phone_number_2)), html::input('hidden', 'address_id', $data->address_id)]); $card->footer()->add(html::formButtons()); $form->add($card); lucid::$app->response()->replace('#main-fullwidth', $form); }
public function buildPager() { $pager = html::buttonGroup(); #->size('sm'); $pager->add(html::button(html::icon('fast-backward'), 'primary', 'lucid.html.dataTable.page(this,\'first\');')); $pager->add(html::button(html::icon('backward'), 'primary', 'lucid.html.dataTable.page(this,\'previous\');')); $pager->add(html::select(null, $this->currentPage, $this->buildPagerOptions(), "lucid.html.dataTable.page(this,this.options[this.selectedIndex].value);")); $pager->lastChild()->modifier('primary'); $pager->add(html::button(html::icon('forward'), 'primary', 'lucid.html.dataTable.page(this,\'next\');')); $pager->add(html::button(html::icon('fast-forward'), 'primary', 'lucid.html.dataTable.page(this,\'last\');')); return html::span()->addClass('data-table-pager')->add($pager); }