Html Module

Uit Covide

Ga naar: navigatie, zoeken

As described earlier, the html module is required for generating html output which is an indispensable requirement for every output. The brief discussion is because of the importance of the module.

Inhoud

Adding tags

The syntax for addTag function is::</br>

addTag->($tagname, $settings);

where $tagname is html tag “div”, “span”, etc. and $settings is an array with the settings of the tag.</br>

To get the output,</br>

<div class=”topbanner” id=”topBannerLeft”>Here is some data!</div>
Following codes will be necessary: </br>
$output = new Layout_output(); //initialize the Layout_output class</br>
$output->addTag("div", array("class" => " topbanner", "id" => " topBannerLeft"));</br>
$output->addCode(“Here is some data!”);</br>
$output->endTag(“div”);

Adding javascript snippets

To add javascript </br>

<script type=’text/javascript’>
 function test()
 {
 	 //function content here
 }
 </script>

One has to write the following code:

$output = new Layout_output(); //initialize the Layout_output class </br>
$output->start_javascript();
$output->addCode("
    function test() {
        //content here
    }
  ");
$output->end_javascript();

Inserting images

The following is done to insert image:

$output->insertImage($path_to_image, $title, $link, $theme_id); 

where path to image starts from themes/<$theme_id>/$path_to_image, $title is the string title of the image, $link is the link if necessary to the image,

Adding css

To add css, following command would be necessay:

$output->css($theme_id);

where $theme_id is optional, and loads the default css if not set, else loads the css respective to the theme.

Adding javascript link

To add a link to an external js file, do the following:

$output->load_javascript($path_to_js_file);

Inserting table

Please have a look at Layout_table class for more details.

<table>
    <tr>
     <td>
	 Table with a single row and no settings!
     </td>
    </tr>
</table>

This code will be required for the above table:

$table = new Layout_table($settings);
 $table->addTableRow();
  $table->addTableData();
    $table->addCode(“Table with a single row and no settings!”);
  $table->endTableData();
 $table->endTableRow();
$table->endTable();

Inserting link

The following code will be necessary to add links:

$output->insertLink($name, $settings, $skip_encodings);

where $settings and $skip_encodings are optional fields

For example, for the link,

<a href=’?mod=desktop’ onclick=’return confirm(“Are you sure?”)’>Exit</exit>

the code will be necessary,

$output->insertLink(“Exit”, array("href" => “?mod=desktop”, “confirm” => ”Are you sure?”));

Adding Form Fields

The following functions of Layout_output class are used for adding form fields:

• insertButton($text, $alt, $link);
• insertCheckbox($name, $value, $checked=0, $view_compatible=0);
• addRadioField($name, $label, $value, $selected_value, $id="", $onclick="");
• addTextField($name, $value, $settings="", $id="", $allow_enters=0);
• addUploadField($name, $settings="", $id="");
• addPasswordField($name, $value, $settings="", $id="");
• addTextArea($name, $value, $settings="", $id="");
• addHiddenField($name, $value, $id="");
• addSelectField($name, $values, $selected_values="", $multiple = 0, $settings="", $id="");

where $name refers to the field names, $value(s) refers to the value of the field, $settings is the settings array, etc. For more details, please have a look at Layout_output class.

Adding venster screen

Here’s a simple implementation of a venster screen. Please have a look at Layout_venster class for more details.

$venster = new Layout_venster(array(
		"title"    => “Test Popup”,
		"subtitle" => “Popup description”
));//starts a venster with settings title and subtitle
$venster->addVensterData();
	//Add HTML here…
$venster->endVensterData();

Adding an editor

To add an editor, browser version needs to be checked. Please check Layout_editor for further details.

Addition of sample editor:

$editor = new Layout_editor();
$ret = $editor->generate_editor(1);	//1 to load the mini version of the tinymce with font supports
if ($ret !== false) {	//$ret = false implies that the browser does not support editors
	$output->addTextArea($name, $value, $settings, “content”);	//id is content by default
	$output->addCode($ret);
} else {
	$ output->addTextArea($name, $value, $settings);
}

Page header/footer

The files “page_header.php” and “page_footer.php” inside “html/inc” folders are used for page headers and footers.

Adding/Deleting navigation items

To add a navigation item, Layout_navigation class is used.

$navigation = new Layout_navigation();
$navigation->addNavigationItem($navigationName, $classForImage, $navigationLink);

where $navigationName is the name of the link, $classForImage is the respective class required to display the icon of the navigation and $navigationLink is the navigation link.

Mappings

Mappings (and complex mappings) are a way to display multiple data records to the user's screen in a table. The mapping functions are found in the classes\html\view.php file.

They are initialised by code similar to this:

/* get the data we need */
$part  =  $mailData->getEmailBySearch($options, $list_from, $_REQUEST["sort"]);
$data  =& $part["data"];

/* create a new view and add the data */
$view = new Layout_view();
$view->addData($data);

The mapping functions are found in the classes\html\view.php file.

After initialising the Layout_View object, you need to specify the columns:

$view->addMapping("  ", "%%is_new");
$view->addMapping(gettext("subject"), "%%data_subject");
$view->addMapping(" ", "%%complex_flags");

Then, actual data is added to these columns:

/* Define complex mapping for is_new */
$view->defineComplexMapping("is_new", array(
array(
	"type"  => "action",
	"src"   => "mail_new",
	"check" => "%is_new",
	"alt"   => gettext("this email is unread")
)
));

/* Define complex mapping for complex flags */
$view->defineComplexMapping("complex_flags", array(
	array(
		"type"  => "action",
		"src"   => "mail_headers",
		"check" => "%h_description",
		"alt"   => gettext("this email has a remark"),
		"link" => array($popup1, "?mod=email&action=$_action&sort=".$_REQUEST["sort"]."&id=", "%id", $popup2)
	),
	array(
		"type"  => "action",
		"src"   => "attachment",
		"check" => "%has_attachments",
		"alt"   => gettext("this email has attachements"),
		"link"  => array($popup1, "?mod=email&action=$_action&sort=".$_REQUEST["sort"]."&id=", "%id", $popup2)
	),
));

/* define complex mapping for subject */
$view->defineComplexMapping("data_subject", array(
	array(
		"type" => "text",
		"text" => array("<div id=\"preview_", "%id", "\">")
	),
	array(
		"type" => "link",
		"text" => "%subject",
		"link"  => array($popup1, "?mod=email&action=$_action&sort=".$_REQUEST["sort"]."&address_id=".$_REQUEST['address_id']."&folder_id=".$_REQUEST['folder_id']."&project_id=".$_REQUEST['project_id']."&id=", "%id", $popup2)
	),
	array(
		"type" => "text",
		"text" => "</div>"
	),
	array(
		"type" => "text",
		"text" => array("<div id=\"contentpreview_", "%id", "\" class=\"previewcontent\" style=\"position: absolute;\"><p>", "%h_body", "</p></div>"),
	),
));

Finally, the code has to be added to the screen through Layout_View->generate_output() or Layout_View->generate_output_vertical().

Text with a single % will output a value from the dataset; so $data[0]["test"] will be inserted in the table when %test is used. A %% refers to the name of a complex mapping (as used in the example above).

Teruggeplaatst van "http://wiki.covide.nl/Html_Module"
Persoonlijke instellingen