From e4c112563fd44c4394a202319095e4fb824ecc1a Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Thu, 26 Feb 2015 14:53:22 -0600 Subject: [PATCH] lists: truncate properties, add item search --- .../staff/templates/list-item-row.tmpl.php | 4 +- include/staff/templates/list-items.tmpl.php | 40 ++++++++++++++++--- scp/js/scp.js | 2 +- scp/lists.php | 1 + 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/include/staff/templates/list-item-row.tmpl.php b/include/staff/templates/list-item-row.tmpl.php index 7df1517ef..267cb1e5e 100644 --- a/include/staff/templates/list-item-row.tmpl.php +++ b/include/staff/templates/list-item-row.tmpl.php @@ -32,6 +32,8 @@ </td> <?php $props = $item->getConfiguration(); foreach ($prop_fields as $F) { ?> - <td><?php echo $F->display($props[$F->get('id')]); ?></td> + <td style="max-width: 20%"><span class="truncate"><?php + echo $F->display($props[$F->get('id')]); + ?></span></td> <?php } ?> </tr> diff --git a/include/staff/templates/list-items.tmpl.php b/include/staff/templates/list-items.tmpl.php index e9d685024..e57a8bf09 100644 --- a/include/staff/templates/list-items.tmpl.php +++ b/include/staff/templates/list-items.tmpl.php @@ -11,9 +11,25 @@ else $showing = __('Add a few initial items to the list'); ?> <div style="margin: 5px 0"> - <div class="pull-left"><em><?php echo $showing; ?></em></div> + <div class="pull-left"> + <input type="search" size="25" id="search" value="<?php + echo Format::htmlchars($_POST['search']); ?>"/> + <button type="submit" onclick="javascript: + event.preventDefault(); + $.pjax({type: 'POST', data: { search: $('#search').val() }, container: '#pjax-container'}); + return false; +"><?php echo __('Search'); ?></button> + <?php if ($_POST['search']) { ?> + <a href="#" onclick="javascript: + $.pjax.reload('#pjax-container'); return false; " + ><i class="icon-remove-sign"></i> <?php + echo __('clear'); ?></a> + <?php } ?> + </div> + <?php if ($list) { ?> <div class="pull-right"> - <?php if (!$list || $list->allowAdd()) { ?> + <em style="display:inline-block; padding-bottom: 3px;"><?php echo $showing; ?></em> + <?php if ($list->allowAdd()) { ?> <a class="action-button field-config" href="#list/<?php echo $list->getId(); ?>/item/add"> @@ -45,6 +61,7 @@ </ul> </div> </div> + <?php } ?> <div class="clear"></div> </div> @@ -66,10 +83,10 @@ if ($list) { } ?> - <table class="form_table" width="940" border="0" cellspacing="0" cellpadding="2"> + <table class="form_table fixed" width="940" border="0" cellspacing="0" cellpadding="2"> <thead> <tr> - <th width="8" nowrap></th> + <th width="24" nowrap></th> <th><?php echo __('Value'); ?></th> <?php foreach ($prop_fields as $F) { ?> <th><?php echo $F->getLocal('label'); ?></th> @@ -77,13 +94,22 @@ if ($list) { </tr> </thead> - <tbody <?php if ($list->get('sort_mode') == 'SortCol') { ?> + <tbody <?php if (!isset($_POST['search']) && $list && $list->get('sort_mode') == 'SortCol') { ?> class="sortable-rows" data-sort="sort-"<?php } ?>> <?php if ($list) { $icon = ($list->get('sort_mode') == 'SortCol') ? '<i class="icon-sort"></i> ' : ''; - $items = $pageNav->paginate($list->getAllItems()); + $items = $list->getAllItems(); + if ($_POST['search']) { + $items->filter(Q::any(array( + 'value__contains'=>$_POST['search'], + 'extra__contains'=>$_POST['search'], + 'properties__contains'=>$_POST['search'], + ))); + $search = true; + } + $items = $pageNav->paginate($items); // Emit a marker for the first sort offset ?> <input type="hidden" id="sort-offset" value="<?php echo max($items[0]->sort, $pageNav->getStart()); ?>"/> @@ -94,6 +120,8 @@ if ($list) { } ?> </tbody> </table> +<?php if ($pageNav && $pageNav->getNumPages()) { ?> <div><?php echo __('Page').':'.$pageNav->getPageLinks('items', $pjax_container); ?></div> +<?php } ?> </div> diff --git a/scp/js/scp.js b/scp/js/scp.js index 9ac9e8f73..5e4998976 100644 --- a/scp/js/scp.js +++ b/scp/js/scp.js @@ -152,7 +152,7 @@ var scp_prep = function() { } }; - $("form#save :input").change(function() { + $("form#save :input[name]").change(function() { if (!$(this).is('.nowarn')) warnOnLeave($(this)); }); diff --git a/scp/lists.php b/scp/lists.php index 0d99e9cfc..628e60b05 100644 --- a/scp/lists.php +++ b/scp/lists.php @@ -132,6 +132,7 @@ if($_POST) { } } break; + case 'import-items': if (!$list) { $errors['err']=sprintf(__('%s: Unknown or invalid ID.'), -- GitLab