Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagephp
class MyModule extends Module {
...
	public function getPackageFields($vars=null) {
		// Load any helpers required to build the fields
		Loader::loadHelpers($this, array("Html"));
		
		// Set any module fields
		$fields = new ModuleFields();
		$fields->setHtml("
			<script type=\"text/javascript\">
				$(document).ready(function() {
					// Re-fetch module options
					$('#mymodule_group').change(function() {
						fetchModuleOptions();
					});
				});
			</script>
		");

		// Fetch all packages available for the given server or server group
		$module_row = null;
		if (isset($vars->module_group) && $vars->module_group == "") {
			// Set a module row if one is given
			if (isset($vars->module_row) && $vars->module_row > 0)
				$module_row = $this->getModuleRow($vars->module_row);
			else {
				// Set the first module row of any that exist
				$rows = $this->getModuleRows();
				if (isset($rows[0]))
					$module_row = $rows[0];
				unset($rows);
			}
		}
		else {
			// Set the first module row from the list of servers in the selected group
			$rows = $this->getModuleRows($vars->module_group);
			if (isset($rows[0]))
				$module_row = $rows[0];
			unset($rows);
		}

		// Build any HTML fields
		$select_options = array('one' => "One", 'two', => "Two");
		$field = $fields->label(Language::_("MyModule.package_fields.field1", true), "mymodule_field");
		$field->attach($fields->fieldSelect("meta[field]", $select_options, 
			$this->Html->ifSet($vars->meta['field']), array('id' => "mymodule_field")));
		$fields->setField($field);

		return $fields;
	}
...
}

...