public static function app_nav($in_nav_def) { ?> <div class="nav-app"> <?php print '<ul>'; foreach ($in_nav_def as $nav_item) { $resource_id = $nav_item['resource']; $action_uri = JxWui::base_url() . JxWuiUtil::trim_slashes($resource_id); print '<li><a href="' . $action_uri . '"' . ($action_uri == $_SERVER['REQUEST_URI'] ? ' class="current"' : '') . '>' . $nav_item['title'] . '</a></li>'; } print '<li><a href="">Extra Test 1</a></li>'; print '<li><a href="">Extra Test 2</a></li>'; print '</ul>'; ?> </div><?php }
private final function generate_head() { ?> <!DOCTYPE html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" type="text/css" href="<?php print JxWui::resource_url(); ?> css/shtml.css"> <script type="text/javascript" src="<?php print JxWui::resource_url(); ?> js/shtml.js"></script> <?php $this->generate_module_head(); ?> </head> <body> <?php }
public static function adorn_request_desc(&$request) { $base_url = JxWui::base_url(); $uri_no_query = strtok($_SERVER["REQUEST_URI"], '?'); $request['resource-id'] = substr($uri_no_query, strlen($base_url)); if ($request['resource-id'] === false) { $request['resource-id'] = ''; } if (!$request['method']) { switch ($_SERVER['REQUEST_METHOD']) { case 'GET': $request['method'] = 'QUERY'; break; case 'POST': $request['method'] = 'CREATE'; break; case 'PUT': $request['method'] = 'UPDATE'; break; case 'DELETE': $request['method'] = 'DELETE'; break; } } $filter = array(); $filter_params = explode('&', $_SERVER['QUERY_STRING']); foreach ($filter_params as $param) { $parts = explode('=', $param, 2); if (count($parts) == 1) { $filter[$parts[0]] = ''; } else { if (count($parts) == 2) { $filter[$parts[0]] = $parts[1]; } } } $request['filter'] = $filter; return $request; }
public function generate_module_head() { ?> <title><?php print $this->manifest['title']; ?> </title> <script type="text/javascript"> <?php $container_path = $this->manifest['container-id']; print 'var close_uri="' . JxWui::base_url() . JxWuiUtil::trim_slashes($container_path) . '";'; ?> function do_close() { location.href = close_uri; } function do_save() { document.getElementById('content-form').submit(); } function toggle_pane(in_value) { document.getElementById('pane-0').style.visibility = 'hidden'; document.getElementById('pane-1').style.visibility = 'hidden'; document.getElementById('pane-'+in_value).style.visibility = 'visible'; } </script> <style type="text/css"> form#content-form { height: 70%; margin-bottom: 30px; padding: 0; margin-top: 10px; } textarea#content { width: 100%; height: 100%; font-family: 'Courier New', monospace; font-size: 10pt; } div.panes { position: relative; width: 100%; height: 100%; } div.pane { position: absolute; left: 0; top: 0; width: 100%; height: 100%; } div.pane:not(:first-child) { visibility: hidden; } </style><?php }
public static function run() { JxWui::begin_http_session(); /* if the request method might indicate form url-encoded data and the content type is not JSON, we need to first transcode the request from HTTP to JSON */ if ($_SERVER['REQUEST_METHOD'] != 'GET' && $_SERVER['CONTENT_TYPE'] != 'application/json') { JxWui::load_screen($_SESSION['prev_screen']); JxWui::load_layout(JxWui::$screen_manifest['layout']); $null = NULL; JxWui::$screen_layout->configure(JxWui::$screen_manifest, $null); $request = JxWui::$screen_layout->generate_rest(); } else { $request = array(); } JxWuiRestHandler::adorn_request_desc($request); $response = JxWuiRestHandler::get_appication_response($request); JxWui::load_screen($response['screen']); JxWui::load_layout(JxWui::$screen_manifest['layout']); JxWui::$screen_layout->configure(JxWui::$screen_manifest, $response); JxWui::$screen_layout->generate_screen($response); }
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ require dirname(__FILE__) . '/jx-wui/init.php'; function url_base_admin() { return dirname($_SERVER['PHP_SELF']) . '/'; } // application registers various things with the WUI toolkit JxWui::configure('jx-cms', url_base_admin(), dirname(__FILE__) . '/'); //JxWuiRestHandler::register('/articles/*/attrs', array('admin', 'handler_articles')); JxWuiRestHandler::register('/articles/*', array('admin', 'handler_articles')); JxWuiRestHandler::register('/', array('admin', 'handler_default')); // the other way a request can come in is as ajax, but we're not going to do that yet // so we just want to handle a HTTP request GET/POST // and identify that it's not JSON (origin the WUI form) JxWui::run(); class Admin { public static function handler_default($request) { $response = array('screen' => 'articles-list'); $response['row-map'] = array('id', 'title', 'status', 'date', 'author'); $response['row-data'] = array(array(1, 'Hello World!', 'Published', '2015-12-16', 'Josh Hawcroft'), array(2, 'Second Article', 'Draft', '2015-12-17', 'Josh Hawcroft')); return $response; } public static function handler_articles($request) { $response = array('screen' => 'article-detail'); $response['content'] = "Hello world. This is a short demo article."; $response['featured'] = false; $response['when'] = '2015-12-17 23:51:49';
public function generate_module() { ?> <h1><?php print $this->manifest['title']; ?> </h1> <table class="widget-list"> <thead><tr><?php /* begin configuring the displated columns */ $column_definitions = $this->manifest['column-definitions']; $columns = array(); $index = 0; if ($this->manifest['has-selectors']) { $columns[] = ':selector'; /* a special row selector checkbox */ $index++; } /* check if we have a saved column configuration for this screen; otherwise, use defaults */ $nominated = $this->manifest['default-columns']; // ought to query configuration here // from JxWui - which will itself query the application, via standard REST /* index the user-nominated/default set of column definitions in the requested sequence */ $col_map = array(); foreach ($nominated as $column_id) { $def = $column_definitions[$column_id]; $def['ui-index'] = $index; $def['id'] = $column_id; $columns[] = $def; $col_map[$column_id] = $index++; } /* output each column header */ foreach ($columns as $column) { if ($column === ':selector') { print '<td width="30"><input type="checkbox"></td>'; } else { print '<td>'; print $column['caption']; print '</td>'; } } ?> </tr></thead> <tbody><?php /* map the currently displayed column sequence to the order the column values are provided in each data row */ $row_map = $this->data['row-map']; $index = 0; $resource_id_index = 0; foreach ($row_map as $column) { if ($column === $this->manifest['resource-id']) { $resource_id_index = $index; } if (isset($col_map[$column])) { $col_idx = $col_map[$column]; $columns[$col_idx]['data-index'] = $index++; } else { $index++; } } /* output each data row */ $row_data = $this->data['row-data']; foreach ($row_data as $row) { print '<tr>'; foreach ($columns as $col) { $action_uri = ''; if (isset($col['action'])) { switch ($col['action'][0]) { case 'query': $resource_id = $row[$resource_id_index]; $action_uri = str_replace(':id', $resource_id, $this->manifest['resource-path']); $action_uri = JxWui::base_url() . JxWuiUtil::trim_slashes($action_uri); break; } } if ($col === ':selector') { print '<td><input type="checkbox"></td>'; } else { $value = $row[$col['data-index']]; print '<td>'; if ($action_uri != '') { print '<a href="' . $action_uri . '">'; } print $value; if ($action_uri != '') { print '</a>'; } print '</td>'; } } print '</tr>'; } ?> </tbody> </table> <!-- <pre> <?php var_dump($columns); ?> </pre> --> <?php }