From cf4daf1e66419818359c33ae194c1c175026b07d Mon Sep 17 00:00:00 2001 From: Michael Slone Date: Wed, 22 Jul 2015 14:53:15 -0400 Subject: [PATCH 1/8] Add visual selector for item relations. Author: Gero Zahn Author: Michael Slone (cosmetic changes only) --- item_relations_form.php | 99 ++++++- item_relations_script.js | 187 +++++++++++++ item_relations_styles.css | 12 + languages/template.pot | 30 +- lity/lity.css | 160 +++++++++++ lity/lity.js | 373 +++++++++++++++++++++++++ lity/lity.min.css | 3 + lity/lity.min.js | 4 + models/Table/ItemRelationsProperty.php | 2 +- 9 files changed, 855 insertions(+), 15 deletions(-) create mode 100644 item_relations_script.js create mode 100644 item_relations_styles.css create mode 100644 lity/lity.css create mode 100644 lity/lity.js create mode 100644 lity/lity.min.css create mode 100644 lity/lity.min.js diff --git a/item_relations_form.php b/item_relations_form.php index 5ee0fda..263bcdc 100644 --- a/item_relations_form.php +++ b/item_relations_form.php @@ -1,3 +1,12 @@ +

' @@ -38,20 +47,84 @@ formSelect('item_relations_property_id[]', null, array('multiple' => false), $formSelectProperties); ?> - formText('item_relations_item_relation_object_item_id[]', null, array('size' => 8)); ?> - n/a + + +
+ []
+ formText('item_relations_item_relation_object_item_id[]', null, array('size' => 8)); ?> +
+ + - + + + + +\n"; + // --- 1. Fetch all item typs together with ther IDs and names + if (defined("SIMULATION")) { + $itemtypes=array(); + for($i=1; ($i<=SIM_CATEGORIES); $i++) { $itemtypes[]=array("id" => $i, "name" => substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, SIM_CATLEN)); } + } + else { + $sql = "SELECT id, name from {$db->Item_Types} ORDER BY id"; + $itemtypes = $db->fetchAll($sql); + } + $lines=array(); + $lines[]="0:'".__("[n/a]")."'"; + foreach($itemtypes as $itemtyp) { + $lines[]=$itemtyp["id"].":'".htmlspecialchars($itemtyp["name"], ENT_QUOTES)."'"; + } + // JavaScript object + echo "var itemTypes={\n". + implode(",\n",$lines)."\n". + "};\n"; + // --- 2. Fetch all items together with their IDs, titles, and item type IDs and names + if (defined("SIMULATION")) { + $items=array(); + for($i=1; ($i<=SIM_ITEMS); $i++) { + $items[]=array($i, substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, SIM_ITEMLEN), rand(0,SIM_CATEGORIES), time()-rand(0,3600)); + } + usort($items, function($a, $b) { return ( $a[2]!=$b[2] ? $a[2]-$b[2] : ( $a[1]!=$b[1] ? ($a[1]>$b[1] ? 1 : -1 ) : 0 ) ); } ); + } + else { + $item_id_suffix=($item->id ? "and items.id<>".$item->id : "" ); + $sql = "SELECT items.id, text, item_type_id, UNIX_TIMESTAMP(modified) + FROM {$db->Item} items + LEFT JOIN {$db->Element_Texts} elementtexts on (items.id=elementtexts.record_id) + WHERE elementtexts.element_id=50 $item_id_suffix + GROUP BY elementtexts.record_id + ORDER BY items.item_type_id ASC, text ASC"; + $items = $db->fetchAll($sql); + } + // For efficiency, we use a regular JavaScript array notation instead of JSON + $lines=array(); + foreach($items as $item) { + foreach (array_keys($item) as $key) { + if (!$item[$key]) { $item[$key]=0; } # Transform all empty values to zero + if (intval($item[$key])!==$item[$key]) { $item[$key]="'".htmlspecialchars($item[$key], ENT_QUOTES)."'"; } # Non-ints i.e. string into apostrophes + } + $lines[]="[[".implode("],[", $item)."]]"; # Item as a new array element - with its components in another array + } + echo "var allItemsArr=[\n". + implode(",\n",$lines)."\n". + "];\n"; + // -------- + echo "var itemTypesTxt='".__("Item Types")."';\n"; + echo "var allTxt='".__("All")."';\n"; + echo "var itemTypeTxt='".__("Item Type")."';\n"; + echo "var sortWithinItemTypeByTxt='".__("Sort within item types by")."';\n"; + echo "var updDateDescTxt='".__("Last Update (desc)")."';\n"; + echo "var nameAscTxt='".__("Name (asc)")."';\n"; + echo "var searchTermTxt='".__("Search Term")."';\n"; + echo "var resetTxt='".__("Reset")."';\n"; + echo "\n"; + # echo "$sql
\n"; +?> +

diff --git a/item_relations_script.js b/item_relations_script.js new file mode 100644 index 0000000..2f156ac --- /dev/null +++ b/item_relations_script.js @@ -0,0 +1,187 @@ +jQuery(document).ready(function () { + + var $ = jQuery; // use noConflict version of jQuery as the short $ within this block + var lightbox = lity(); // Lity lightbox for item selector "popup" + + var my_input = null; // Reference to currently active input + var allItemsSortedArr = null; // Room for a pre-sorted array + var filterItemTyp = null; // Room for filter by type + var curListOrder = null; // Room for sort order + var curFilter = null; // Room for filter word + + // --- START: moved from + -\n"; - // --- 1. Fetch all item typs together with ther IDs and names - if (defined("SIMULATION")) { - $itemtypes=array(); - for($i=1; ($i<=SIM_CATEGORIES); $i++) { $itemtypes[]=array("id" => $i, "name" => substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, SIM_CATLEN)); } - } - else { - $sql = "SELECT id, name from {$db->Item_Types} ORDER BY id"; - $itemtypes = $db->fetchAll($sql); - } - $lines=array(); - $lines[]="0:'".__("[n/a]")."'"; - foreach($itemtypes as $itemtyp) { - $lines[]=$itemtyp["id"].":'".htmlspecialchars($itemtyp["name"], ENT_QUOTES)."'"; - } - // JavaScript object - echo "var itemTypes={\n". - implode(",\n",$lines)."\n". - "};\n"; - // --- 2. Fetch all items together with their IDs, titles, and item type IDs and names - if (defined("SIMULATION")) { - $items=array(); - for($i=1; ($i<=SIM_ITEMS); $i++) { - $items[]=array($i, substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, SIM_ITEMLEN), rand(0,SIM_CATEGORIES), time()-rand(0,3600)); - } - usort($items, function($a, $b) { return ( $a[2]!=$b[2] ? $a[2]-$b[2] : ( $a[1]!=$b[1] ? ($a[1]>$b[1] ? 1 : -1 ) : 0 ) ); } ); - } - else { - $item_id_suffix=($item->id ? "and items.id<>".$item->id : "" ); - $sql = "SELECT items.id, text, item_type_id, UNIX_TIMESTAMP(modified) - FROM {$db->Item} items - LEFT JOIN {$db->Element_Texts} elementtexts on (items.id=elementtexts.record_id) - WHERE elementtexts.element_id=50 $item_id_suffix - GROUP BY elementtexts.record_id - ORDER BY items.item_type_id ASC, text ASC"; - $items = $db->fetchAll($sql); - } - // For efficiency, we use a regular JavaScript array notation instead of JSON - $lines=array(); - foreach($items as $item) { - foreach (array_keys($item) as $key) { - if (!$item[$key]) { $item[$key]=0; } # Transform all empty values to zero - if (intval($item[$key])!==$item[$key]) { $item[$key]="'".htmlspecialchars($item[$key], ENT_QUOTES)."'"; } # Non-ints i.e. string into apostrophes - } - $lines[]="[[".implode("],[", $item)."]]"; # Item as a new array element - with its components in another array - } - echo "var allItemsArr=[\n". - implode(",\n",$lines)."\n". - "];\n"; - // -------- - echo "var itemTypesTxt='".__("Item Types")."';\n"; - echo "var allTxt='".__("All")."';\n"; - echo "var itemTypeTxt='".__("Item Type")."';\n"; - echo "var sortWithinItemTypeByTxt='".__("Sort within item types by")."';\n"; - echo "var updDateDescTxt='".__("Last Update (desc)")."';\n"; - echo "var nameAscTxt='".__("Name (asc)")."';\n"; - echo "var searchTermTxt='".__("Search Term")."';\n"; - echo "var resetTxt='".__("Reset")."';\n"; - echo "\n"; - # echo "$sql
\n"; -?> -
diff --git a/item_relations_script.js b/item_relations_script.js index 1967898..b8522f8 100644 --- a/item_relations_script.js +++ b/item_relations_script.js @@ -1,188 +1,127 @@ jQuery(document).ready(function () { - - var $ = jQuery; // use noConflict version of jQuery as the short $ within this block - var lightbox = lity(); // Lity lightbox for item selector "popup" - - var my_input = null; // Reference to currently active input - var allItemsSortedArr = null; // Room for a pre-sorted array - var filterItemTyp = null; // Room for filter by type - var curListOrder = null; // Room for sort order - var curFilter = null; // Room for filter word - - // --- START: moved from