Revision: 2668
https://sourceforge.net/p/mrbs/code/2668/
Author: cimorrison
Date: 2013-01-31 14:25:47 +0000 (Thu, 31 Jan 2013)
Log Message:
-----------
Introduced a generate_submit() function.
Modified Paths:
--------------
mrbs/branches/linked_bookings/web/admin.php
mrbs/branches/linked_bookings/web/edit_entry.php
mrbs/branches/linked_bookings/web/edit_entry_handler.php
mrbs/branches/linked_bookings/web/functions.inc
Modified: mrbs/branches/linked_bookings/web/admin.php
===================================================================
--- mrbs/branches/linked_bookings/web/admin.php 2013-01-31 12:43:18 UTC (rev
2667)
+++ mrbs/branches/linked_bookings/web/admin.php 2013-01-31 14:25:47 UTC (rev
2668)
@@ -166,25 +166,26 @@
if ($is_admin)
{
// New area form
- ?>
- <form id="add_area" class="form_admin" action="add.php" method="post">
- <fieldset>
- <legend><?php echo get_vocab("addarea") ?></legend>
+ echo "<form id=\"add_area\" class=\"form_admin\" action=\"add.php\"
method=\"post\">\n";
+ echo "<fieldset>\n";
+ echo "<legend>" . get_vocab("addarea") . "</legend>\n";
- <input type="hidden" name="type" value="area">
+ echo "<input type=\"hidden\" name=\"type\" value=\"area\">\n";
- <div>
- <label for="area_name"><?php echo get_vocab("name") ?>:</label>
- <input type="text" id="area_name" name="name" maxlength="<?php echo
$maxlength['area.area_name'] ?>">
- </div>
-
- <div>
- <input type="submit" class="submit" value="<?php echo
get_vocab("addarea") ?>">
- </div>
+ echo "<div>\n";
+ $params = array('label' => get_vocab("name") . ':',
+ 'name' => 'name',
+ 'id' => 'area_name',
+ 'attributes' => 'maxlength="' . $maxlength['area.area_name']
. '"');
+ generate_input($params);
+ echo "</div>\n";
- </fieldset>
- </form>
- <?php
+ echo "<div>\n";
+ generate_submit(array('value' => get_vocab("addarea")));
+ echo "</div>\n";
+
+ echo "</fieldset>\n";
+ echo "</form>\n";
}
echo "</div>"; // area_form
@@ -398,36 +399,42 @@
// there's an area selected
if ($is_admin && $areas_defined && !empty($area))
{
- ?>
- <form id="add_room" class="form_admin" action="add.php" method="post">
- <fieldset>
- <legend><?php echo get_vocab("addroom") ?></legend>
+ echo "<form id=\"add_room\" class=\"form_admin\" action=\"add.php\"
method=\"post\">\n";
+ echo "<fieldset>\n";
+ echo "<legend>" . get_vocab("addroom") . "</legend>\n";
- <input type="hidden" name="type" value="room">
- <input type="hidden" name="area" value="<?php echo $area; ?>">
+ echo "<input type=\"hidden\" name=\"type\" value=\"room\">\n";
+ echo "<input type=\"hidden\" name=\"area\" value=\"$area\">\n";
- <div>
- <label for="room_name"><?php echo get_vocab("name") ?>:</label>
- <input type="text" id="room_name" name="name" maxlength="<?php echo
$maxlength['room.room_name'] ?>">
- </div>
+ echo "<div>\n";
+ $params = array('label' => get_vocab("name") . ':',
+ 'name' => 'name',
+ 'id' => 'room_name',
+ 'attributes' => 'maxlength="' .
$maxlength['room.room_name'] . '"');
+ generate_input($params);
+ echo "</div>\n";
+
+ echo "<div>\n";
+ $params = array('label' => get_vocab("description") . ':',
+ 'name' => 'description',
+ 'id' => 'room_description',
+ 'attributes' => 'maxlength="' .
$maxlength['room.description'] . '"');
+ generate_input($params);
+ echo "</div>\n";
- <div>
- <label for="room_description"><?php echo get_vocab("description")
?>:</label>
- <input type="text" id="room_description" name="description"
maxlength="<?php echo $maxlength['room.description'] ?>">
- </div>
-
- <div>
- <label for="room_capacity"><?php echo get_vocab("capacity")
?>:</label>
- <input type="text" id="room_capacity" name="capacity">
- </div>
+ echo "<div>\n";
+ $params = array('label' => get_vocab("capacity") . ':',
+ 'name' => 'capacity',
+ 'id' => 'room_capacity');
+ generate_input($params);
+ echo "</div>\n";
- <div>
- <input type="submit" class="submit" value="<?php echo
get_vocab("addroom") ?>">
- </div>
+ echo "<div>\n";
+ generate_submit(array('value' => get_vocab("addroom")));
+ echo "</div>\n";
- </fieldset>
- </form>
- <?php
+ echo "</fieldset>\n";
+ echo "</form>\n";
}
echo "</div>\n";
}
Modified: mrbs/branches/linked_bookings/web/edit_entry.php
===================================================================
--- mrbs/branches/linked_bookings/web/edit_entry.php 2013-01-31 12:43:18 UTC
(rev 2667)
+++ mrbs/branches/linked_bookings/web/edit_entry.php 2013-01-31 14:25:47 UTC
(rev 2668)
@@ -1381,13 +1381,18 @@
echo "<legend></legend>\n";
// The Back button
echo "<div id=\"edit_entry_submit_back\">\n";
- echo "<input class=\"submit\" type=\"submit\" name=\"back_button\"
value=\"" . get_vocab("back") . "\" formnovalidate>\n";
+ $params = array('name' => 'back_button',
+ 'value' => get_vocab("back"),
+ 'formnovalidate' => TRUE);
+ generate_submit($params);
echo "</div>\n";
// The Submit button
echo "<div id=\"edit_entry_submit_save\">\n";
- echo "<input class=\"submit default_action\" type=\"submit\"
name=\"save_button\" value=\"" .
- get_vocab("save") . "\">\n";
+ $params = array('name' => 'save_button',
+ 'value' => get_vocab("save"),
+ 'class' => 'default_action');
+ generate_submit($params);
echo "</div>\n";
// divs to hold the results of the Ajax checking of the booking
Modified: mrbs/branches/linked_bookings/web/edit_entry_handler.php
===================================================================
--- mrbs/branches/linked_bookings/web/edit_entry_handler.php 2013-01-31
12:43:18 UTC (rev 2667)
+++ mrbs/branches/linked_bookings/web/edit_entry_handler.php 2013-01-31
14:25:47 UTC (rev 2668)
@@ -706,7 +706,7 @@
// Back button
echo "<form method=\"post\" action=\"" . htmlspecialchars($returl) . "\">\n";
echo "<fieldset><legend></legend>\n";
-echo "<input type=\"submit\" value=\"" . get_vocab("back") . "\">\n";
+generate_submit(array('value' => get_vocab("back")));
echo "</fieldset>\n";
echo "</form>\n";
@@ -747,9 +747,9 @@
}
}
// Submit button
- echo "<input type=\"submit\"" .
- " value=\"" . get_vocab("skip_and_book") . "\"" .
- " title=\"" . get_vocab("skip_and_book_note") . "\">\n";
+ $params = array('value' => get_vocab("skip_and_book"),
+ 'title' => get_vocab("skip_and_book_note"));
+ generate_submit($params);
echo "</fieldset>\n";
echo "</form>\n";
}
Modified: mrbs/branches/linked_bookings/web/functions.inc
===================================================================
--- mrbs/branches/linked_bookings/web/functions.inc 2013-01-31 12:43:18 UTC
(rev 2667)
+++ mrbs/branches/linked_bookings/web/functions.inc 2013-01-31 14:25:47 UTC
(rev 2668)
@@ -624,6 +624,7 @@
// OPTIONAL
// 'label' The text to be used for the field label.
// 'label_title' The text to be used for the title attribute for the
field label
+// 'id' The id of the element. Defaults to the same as the
name.
// 'value' The value of the input. Default ''
// 'type' The type of input, eg 'text', 'number', etc.
Default NULL
// 'step' The value of the 'step' attribute. Default NULL
@@ -651,6 +652,9 @@
case 'name':
trigger_error('Missing mandatory parameters', E_USER_NOTICE);
break;
+ case 'id':
+ $params[$key] = $params['name'];
+ break;
case 'value':
case 'label_title':
$params[$key] = '';
@@ -678,7 +682,7 @@
if (isset($params['label']))
{
// no HTML escaping for the label - it is trusted
- $html .= "<label for=\"" . $params['name'] . "\"";
+ $html .= "<label for=\"" . $params['id'] . "\"";
$html .= (empty($params['label_title'])) ? '' : ' title="' .
htmlspecialchars($params['label_title']) . '"';
$html .= ">" . $params['label'] . "</label>\n";
}
@@ -689,7 +693,7 @@
$html .= (isset($params['max'])) ? " max=\"" . $params['max'] . "\"" : "";
$html .= (isset($params['pattern'])) ? " pattern=\"" .
htmlspecialchars($params['pattern']) . "\"" : "";
$html .= (isset($params['attributes'])) ? " " . $params['attributes'] : "";
- $html .= " id=\"" . $params['name'] . "\" name=\"" . $params['name'] . "\"";
+ $html .= " id=\"" . $params['id'] . "\" name=\"" . $params['name'] . "\"";
$html .= ($params['disabled']) ? " disabled=\"disabled\"" : '';
$html .= ($params['mandatory']) ? " required aria-required=\"true\"" : '';
$html .= (isset($params['maxlength'])) ? " maxlength=\"" .
$params['maxlength'] . "\"" : '';
@@ -1422,6 +1426,62 @@
echo $html;
}
+
+function generate_submit($params)
+{
+ // some sanity checking on params
+ foreach (array('name', 'value', 'title', 'class', 'disabled',
'formnovalidate') as $key)
+ {
+ if (!isset($params[$key]))
+ {
+ switch ($key)
+ {
+ case 'value':
+ trigger_error('Missing mandatory parameters', E_USER_NOTICE);
+ break;
+ case 'class':
+ $params[$key] = array();
+ break;
+ case 'disabled':
+ case 'formnovalidate':
+ $params[$key] = FALSE;
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ if (!is_array($params['class']))
+ {
+ $params['class'] = array($params['class']);
+ }
+ $params['class'][] = 'submit';
+
+ $html = "<input type=\"submit\"";
+ if (count($params['class']) > 0)
+ {
+ $html .= " class=\"" . implode(' ', $params['class']) . "\"";
+ }
+ if (isset($params['name']))
+ {
+ $html .= " name=\"" . $params['name'] . "\"";
+ }
+ if (isset($params['title']))
+ {
+ $html .= " title=\"" . $params['title'] . "\"";
+ }
+ $html .= " value=\"" . htmlspecialchars($params['value']) . "\"";
+ if ($params['formnovalidate'])
+ {
+ $html .= " formnovalidate";
+ }
+ $html .= ">\n";
+
+ echo $html;
+}
+
+
// Generates a date selector for use on a form. If JavaScript is enabled
// then it will generate a calendar picker using jQuery UI datepicker. If
not,
// it will generate three separate select boxes, one each for day, month and
year.
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits