Example #1
0
 /**
  * Return the Edit Form as HTML
  * @return
  */
 public function EditForm()
 {
     $this->response = new ResponseManager();
     // Edit calls are the same as add calls, except you will to check the user has permissions to do the edit
     if (!$this->auth->edit) {
         $this->response->SetError('You do not have permission to edit this assignment.');
         $this->response->keepOpen = false;
         return $this->response;
     }
     // All forms should set some meta data about the form.
     // Usually, you would want this meta data to remain the same.
     Theme::Set('form_id', 'ModuleForm');
     Theme::Set('form_action', 'index.php?p=module&mod=' . $this->type . '&q=Exec&method=EditMedia');
     Theme::Set('form_meta', '<input type="hidden" name="layoutid" value="' . $this->layoutid . '"><input type="hidden" id="iRegionId" name="regionid" value="' . $this->regionid . '"><input type="hidden" name="showRegionOptions" value="' . $this->showRegionOptions . '" /><input type="hidden" id="mediaid" name="mediaid" value="' . $this->mediaid . '">');
     // Augment settings with templates
     $this->loadTemplates();
     // Two tabs
     $tabs = array();
     $tabs[] = FormManager::AddTab('general', __('General'));
     $tabs[] = FormManager::AddTab('advanced', __('Appearance'));
     $tabs[] = FormManager::AddTab('forecast', __('Forecast'));
     Theme::Set('form_tabs', $tabs);
     $formFields['general'][] = FormManager::AddText('name', __('Name'), $this->GetOption('name'), __('An optional name for this media'), 'n');
     $formFields['general'][] = FormManager::AddNumber('duration', __('Duration'), $this->duration, __('The duration in seconds this item should be displayed.'), 'd', 'required');
     $formFields['general'][] = FormManager::AddCheckbox('useDisplayLocation', __('Use the Display Location'), $this->GetOption('useDisplayLocation'), __('Use the location configured on the display'), 'd');
     // Any values for the form fields should be added to the theme here.
     $formFields['general'][] = FormManager::AddNumber('latitude', __('Latitude'), $this->GetOption('latitude'), __('The Latitude for this weather module'), 'l', '', 'locationControls');
     $formFields['general'][] = FormManager::AddNumber('longitude', __('Longitude'), $this->GetOption('longitude'), __('The Longitude for this weather module'), 'g', '', 'locationControls');
     $formFields['advanced'][] = FormManager::AddCombo('templateId', __('Weather Template'), $this->GetOption('templateId'), $this->settings['templates'], 'id', 'value', __('Select the template you would like to apply. This can be overridden using the check box below.'), 't', 'template-selector-control');
     $formFields['advanced'][] = FormManager::AddCombo('icons', __('Icons'), $this->GetOption('icons'), $this->iconsAvailable(), 'id', 'value', __('Select the icon set you would like to use.'), 't', 'icon-controls');
     $formFields['advanced'][] = FormManager::AddNumber('size', __('Size'), $this->GetOption('size', 1), __('Set the size. Start at 1 and work up until the widget fits your region appropriately.'), 's', 'number', 'template-selector-control');
     $formFields['advanced'][] = FormManager::AddCombo('units', __('Units'), $this->GetOption('units'), $this->unitsAvailable(), 'id', 'value', __('Select the units you would like to use.'), 'u');
     $formFields['advanced'][] = FormManager::AddCombo('lang', __('Language'), $this->GetOption('lang', TranslationEngine::GetLocale(2)), $this->supportedLanguages(), 'id', 'value', __('Select the language you would like to use.'), 'l');
     $formFields['advanced'][] = FormManager::AddNumber('updateInterval', __('Update Interval (mins)'), $this->GetOption('updateInterval', 60), __('Please enter the update interval in minutes. This should be kept as high as possible. For example, if the data will only change once per hour this could be set to 60.'), 'n', 'required');
     $formFields['advanced'][] = FormManager::AddCheckbox('dayConditionsOnly', __('Only show Daytime weather conditions'), $this->GetOption('dayConditionsOnly', 1), __('Tick if you would like to only show the Daytime weather conditions.'), 'd');
     $formFields['general'][] = FormManager::AddText('color', __('Colour'), $this->GetOption('color', '000'), __('Please select a colour for the foreground text.'), 'c', 'required');
     $formFields['advanced'][] = FormManager::AddCheckbox('overrideTemplate', __('Override the template?'), $this->GetOption('overrideTemplate'), __('Tick if you would like to override the template.'), 'o');
     $formFields['advanced'][] = FormManager::AddMultiText('currentTemplate', __('Template for Current Forecast'), $this->GetRawNode('currentTemplate'), __('Enter the template for the current forecast. For a list of substitutions click "Request Forecast" below.'), 't', 10, 'required', 'template-override-controls');
     $formFields['advanced'][] = FormManager::AddMultiText('dailyTemplate', __('Template for Daily Forecast'), $this->GetRawNode('dailyTemplate'), __('Enter the template for the current forecast. Replaces [dailyForecast] in main template.'), 't', 10, NULL, 'template-override-controls');
     $formFields['advanced'][] = FormManager::AddMultiText('styleSheet', __('CSS Style Sheet'), $this->GetRawNode('styleSheet'), __('Enter a CSS style sheet to style the weather widget'), 'c', 10, 'required', 'template-override-controls');
     $formFields['forecast'][] = FormManager::AddMessage(__('Please press Request Forecast to show the current forecast and all available substitutions.'));
     // Encode up the template
     if (Config::GetSetting('SERVER_MODE') == 'Test' && $this->user->usertypeid == 1) {
         $formFields['forecast'][] = FormManager::AddMessage('<pre>' . htmlentities(json_encode(array('id' => 'ID', 'value' => 'TITLE', 'main' => $this->GetRawNode('currentTemplate'), 'daily' => $this->GetRawNode('dailyTemplate'), 'css' => $this->GetRawNode('styleSheet')))) . '</pre>');
     }
     // Configure the field dependencies
     $this->SetFieldDepencencies();
     // Append the Templates to the response
     $this->response->extra = $this->settings['templates'];
     // Modules should be rendered using the theme engine.
     Theme::Set('form_fields_general', $formFields['general']);
     Theme::Set('form_fields_advanced', $formFields['advanced']);
     Theme::Set('form_fields_forecast', $formFields['forecast']);
     $this->response->html = Theme::RenderReturn('form_render');
     $this->response->dialogTitle = __('Forecast IO');
     $this->response->callBack = 'forecastIoFormSetup';
     // The response object outputs the required JSON object to the browser
     // which is then processed by the CMS JavaScript library (xibo-cms.js).
     $this->response->AddButton(__('Request Forecast'), 'requestTab("forecast", "index.php?p=module&q=exec&mod=' . $this->type . '&method=requestTab&layoutid=' . $this->layoutid . '&regionid=' . $this->regionid . '&mediaid=' . $this->mediaid . '")');
     $this->response->AddButton(__('Cancel'), 'XiboSwapDialog("index.php?p=timeline&layoutid=' . $this->layoutid . '&regionid=' . $this->regionid . '&q=RegionOptions")');
     $this->response->AddButton(__('Apply'), 'XiboDialogApply("#ModuleForm")');
     $this->response->AddButton(__('Save'), '$("#ModuleForm").submit()');
     // The response must be returned.
     return $this->response;
 }