From 91025d6b7a26fd131ee1853451f7cf0a813cb93f Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 16 Dec 2016 12:05:30 -0800 Subject: [PATCH] web: add utility functions for Bootstrap forms Bootstrap forms require a bunch of
s and other stuff. I wrapped these in functions like form_start() form_end() form_submit() form_select_multiple() form_input_text() General idea going forward: put HTML (especially Bootstrap-specified) in utility functions, e.g. in util.inc or bootstrap.inc. This will make the higher-level code easier to read, and will facilitate moving to CSS frameworks other than Bootstrap. --- html/inc/boinc_db.inc | 48 ++++++++++++++-------------- html/inc/bootstrap.inc | 71 ++++++++++++++++++++++++++++++++++++++++++ html/inc/util.inc | 16 ++++++++-- 3 files changed, 109 insertions(+), 26 deletions(-) diff --git a/html/inc/boinc_db.inc b/html/inc/boinc_db.inc index d3cd4dd5eb..af69168cca 100644 --- a/html/inc/boinc_db.inc +++ b/html/inc/boinc_db.inc @@ -265,9 +265,9 @@ class BoincTeam { $db = BoincDb::get(); return $db->update($this, 'team', $clause); } - static function enum($clause, $clause2=null) { + static function enum($where_clause, $order_clause=null) { $db = BoincDb::get(); - return $db->enum('team', 'BoincTeam', $clause, $clause2); + return $db->enum('team', 'BoincTeam', $where_clause, $order_clause); } static function lookup($clause) { $db = BoincDb::get(); @@ -303,9 +303,9 @@ class BoincTeamDelta { $db = BoincDb::get(); return $db->insert('team_delta', $clause); } - static function enum($clause) { + static function enum($where_clause) { $db = BoincDb::get(); - return $db->enum('team_delta', 'BoincTeamDelta', $clause); + return $db->enum('team_delta', 'BoincTeamDelta', $where_clause); } } @@ -322,9 +322,9 @@ class BoincHost { $db = BoincDb::get(); return $db->delete($this, 'host'); } - static function enum($clause, $clause2=null) { + static function enum($where_clause, $order_clause=null) { $db = BoincDb::get(); - return $db->enum('host', 'BoincHost', $clause, $clause2); + return $db->enum('host', 'BoincHost', $where_clause, $order_clause); } static function enum_fields($fields, $where_clause, $order_clause=null) { $db = BoincDb::get(); @@ -343,9 +343,9 @@ class BoincResult { $db = BoincDb::get(); return $db->count('result', $clause); } - static function enum($clause) { + static function enum($where_clause) { $db = BoincDb::get(); - return $db->enum('result', 'BoincResult', $clause); + return $db->enum('result', 'BoincResult', $where_clause); } static function enum_fields($fields, $where_clause, $order_clause) { $db = BoincDb::get(); @@ -389,9 +389,9 @@ class BoincWorkunit { if (!$ret) return $ret; return $db->insert_id(); } - static function enum($clause) { + static function enum($where_clause) { $db = BoincDb::get(); - return $db->enum('workunit', 'BoincWorkunit', $clause); + return $db->enum('workunit', 'BoincWorkunit', $where_clause); } function update($clause) { $db = BoincDb::get(); @@ -416,9 +416,9 @@ class BoincApp { $db = BoincDb::get(); return $db->lookup('app', 'BoincApp', $clause); } - static function enum($clause) { + static function enum($where_clause) { $db = BoincDb::get(); - return $db->enum('app', 'BoincApp', $clause); + return $db->enum('app', 'BoincApp', $where_clause); } static function insert($clause) { $db = BoincDb::get(); @@ -437,9 +437,9 @@ class BoincApp { } class BoincAppVersion { - static function enum($clause) { + static function enum($where_clause) { $db = BoincDb::get(); - return $db->enum('app_version', 'BoincAppVersion', $clause); + return $db->enum('app_version', 'BoincAppVersion', $where_clause); } static function lookup($clause) { $db = BoincDb::get(); @@ -486,9 +486,9 @@ class BoincProfile { $db = BoincDb::get(); return $db->insert('profile', $clause); } - static function enum($clause=null, $clause2=null) { + static function enum($where_clause=null, $order_clause=null) { $db = BoincDb::get(); - return $db->enum('profile', 'BoincProfile', $clause, $clause2); + return $db->enum('profile', 'BoincProfile', $where_clause, $order_clause); } static function enum_fields($fields, $where_clause=null, $order_clause=null) { $db = BoincDb::get(); @@ -509,9 +509,9 @@ class BoincTeamAdmin { $db = BoincDb::get(); return $db->insert('team_admin', $clause); } - static function enum($clause) { + static function enum($where_clause) { $db = BoincDb::get(); - return $db->enum('team_admin', 'BoincTeamAdmin', $clause); + return $db->enum('team_admin', 'BoincTeamAdmin', $where_clause); } static function delete($clause) { $db = BoincDb::get(); @@ -532,9 +532,9 @@ class BoincPrivateMessage { $db = BoincDb::get(); return $db->update($this, 'private_messages', $clause); } - static function enum($clause) { + static function enum($where_clause) { $db = BoincDb::get(); - return $db->enum('private_messages', 'BoincPrivateMessage', $clause); + return $db->enum('private_messages', 'BoincPrivateMessage', $where_clause); } static function insert($clause) { $db = BoincDb::get(); @@ -557,9 +557,9 @@ class BoincPrivateMessage { } class BoincPlatform { - static function enum($clause) { + static function enum($where_clause) { $db = BoincDb::get(); - return $db->enum('platform', 'BoincPlatform', $clause); + return $db->enum('platform', 'BoincPlatform', $where_clause); } static function lookup_id($id) { $db = BoincDb::get(); @@ -580,9 +580,9 @@ class BoincPlatform { } class BoincHostAppVersion { - static function enum($clause) { + static function enum($where_clause) { $db = BoincDb::get(); - return $db->enum('host_app_version', 'BoincHostAppVersion', $clause); + return $db->enum('host_app_version', 'BoincHostAppVersion', $where_clause); } static function lookup($host_id, $app_version_id) { $db = BoincDb::get(); diff --git a/html/inc/bootstrap.inc b/html/inc/bootstrap.inc index 7d3e694d7c..ec528cd8b6 100644 --- a/html/inc/bootstrap.inc +++ b/html/inc/bootstrap.inc @@ -266,3 +266,74 @@ function grid($top_func, $left_func, $right_func, $left_width=6) {
'; } + +function form_start($action) { + echo ' +
+ '; +} + +function form_input_hidden($name, $value) { + echo ' + '; +} + +function form_end() { + echo '
+ '; +} + +function form_input_text($label, $name, $value='', $type='text', $attrs='') { + echo ' +
+ +
+ +
+
+ '; +} + +function form_select($label, $name, $items) { + echo ' +
+ +
+
\n"; +} + +// same, for multiple select. +// flags, if non-null, says which ones are selected +// +function form_select_multiple($label, $name, $items, $flags) { + echo ' +
+ +
+
\n"; +} + +function form_submit($text) { + echo ' +
+
+ +
+
+ '; +} diff --git a/html/inc/util.inc b/html/inc/util.inc index d7104fb104..43539ab79b 100644 --- a/html/inc/util.inc +++ b/html/inc/util.inc @@ -470,12 +470,12 @@ function row_array($x) { define ('ALIGN_RIGHT', 'style="text-align:right;"'); -function row_heading_array($x, $attrs=null) { +function row_heading_array($x, $attrs=null, $class='bg-primary') { echo ""; $i = 0; foreach ($x as $h) { $a = $attrs?$attrs[$i]:""; - echo "$h"; + echo "$h"; $i++; } echo "\n"; @@ -672,6 +672,18 @@ function post_int($name, $optional=false) { return $y; } +function get_array($name) { + if (isset($_GET[$name])) { + $x = $_GET[$name]; + } else { + if (!$optional) { + error_page("missing or bad parameter: $name"); + } + $x = null; + } + return $x; +} + function get_str($name, $optional=false) { if (isset($_GET[$name])) { $x = $_GET[$name];