ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilAdvancedSelectionListGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4
12{
13 private $items = array();
14 private $id = "asl";
15 private $asynch = false;
16
17 const DOWN_ARROW_DARK = "down_arrow_dark";
18 const ICON_ARROW = "caret";
19 const ICON_CONFIG = "glyphicon glyphicon-cog";
20 const NO_ICON = "";
21
22 const MODE_LINKS = "links";
23 const MODE_FORM_SELECT = "select";
24
25 const ON_ITEM_CLICK_HREF = "href";
26 const ON_ITEM_CLICK_FORM_SUBMIT = "submit";
27 const ON_ITEM_CLICK_FORM_SELECT = "select";
28 const ON_ITEM_CLICK_NOP = "nop";
29
30 const STYLE_DEFAULT = 0;
31 const STYLE_LINK = 1;
32 const STYLE_EMPH = 2;
34
35 protected $css_row = "";
36 protected $access_key = false;
37 protected $toggle = false;
38 protected $asynch_url = false;
39 protected $selected_value = "";
40 protected $trigger_event = "click";
41 protected $auto_hide = false;
42 protected $grouped_list = null;
43 protected $style = 0;
44 private $dd_pullright = true;
45
46 protected $listtitle;
47 protected $aria_listtitle;
48
49 /*
50
51 The modes implement the following html for non-js fallback:
52
53 MODE_LINKS:
54
55 <a href="...">...</a> <a href="...">...<a>
56
57 MODE_FORM_SELECT: (form and submit tags are optional)
58
59 <form id="..." class="..." method="post" action="..." target="_top">
60 <select name="..." class="..." size="0">
61 <option value="...">...</option>
62 ...
63 </select>
64 <input class="ilEditSubmit" type="submit" value="Go"/>
65 </form>
66
67 */
68
73 public function __construct()
74 {
75 global $DIC;
76
77 $this->lng = $DIC->language();
81 }
82
86 public function setLinksMode($a_link_class = "")
87 {
89 $this->links_mode = array(
90 "link_class" => $a_link_class);
91 }
92
98 public function setFormSelectMode(
99 $a_select_name,
100 $a_select_class = "",
101 $a_include_form_tag = false,
102 $a_form_action = "",
103 $a_form_id = "",
104 $a_form_class = "",
105 $a_form_target = "_top",
106 $a_button_text = "",
107 $a_button_class = "",
108 $a_button_cmd = ""
109 ) {
111 $this->form_mode = array(
112 "select_name" => $a_select_name,
113 "select_class" => $a_select_class,
114 "include_form_tag" => $a_include_form_tag,
115 "form_action" => $a_form_action,
116 "form_id" => $a_form_id,
117 "form_class" => $a_form_class,
118 "form_target" => $a_form_target,
119 "button_text" => $a_button_text,
120 "button_class" => $a_button_class,
121 "button_cmd" => $a_button_cmd
122 );
123 }
124
136 public function addItem(
137 $a_title,
138 $a_value = "",
139 $a_link = "",
140 $a_img = "",
141 $a_alt = "",
142 $a_frame = "",
143 $a_html = "",
144 $a_prevent_background_click = false,
145 $a_onclick = "",
146 $a_ttip = "",
147 $a_tt_my = "right center",
148 $a_tt_at = "left center",
149 $a_tt_use_htmlspecialchars = true,
150 $a_data = array()
151 ) {
152 $this->items[] = array("title" => $a_title, "value" => $a_value,
153 "link" => $a_link, "img" => $a_img, "alt" => $a_alt, "frame" => $a_frame,
154 "html" => $a_html, "prevent_background_click" => $a_prevent_background_click,
155 "onclick" => $a_onclick, "ttip" => $a_ttip, "tt_my" => $a_tt_my, "tt_at" => $a_tt_at,
156 "tt_use_htmlspecialchars" => $a_tt_use_htmlspecialchars, "data" => $a_data);
157 }
158
164 public function setGroupedList($a_val)
165 {
166 $this->grouped_list = $a_val;
167 }
168
174 public function getGroupedList()
175 {
176 return $this->grouped_list;
177 }
178
179 public function flush()
180 {
181 $this->items = array();
182 }
183
189 public function getItems()
190 {
191 return $this->items;
192 }
193
199 public function setListTitle($a_listtitle)
200 {
201 $this->listtitle = $a_listtitle;
202 }
203
209 public function getListTitle()
210 {
211 return $this->listtitle;
212 }
213
219 public function setAriaListTitle($a_listtitle)
220 {
221 $this->aria_listtitle = $a_listtitle;
222 }
223
229 public function getAriaListTitle()
230 {
232 }
233
241 public function setSelectionHeaderClass($a_selectionheaderclass)
242 {
243 $this->selectionheaderclass = $a_selectionheaderclass;
244 }
245
251 public function getSelectionHeaderClass()
252 {
253 return $this->selectionheaderclass;
254 }
255
261 public function setStyle($a_val)
262 {
263 $this->style = $a_val;
264 }
265
271 public function getStyle()
272 {
273 return $this->style;
274 }
275
276
277
283 public function setSelectionHeaderSpanClass($a_val)
284 {
285 $this->sel_head_span_class = $a_val;
286 }
287
294 {
295 return $this->sel_head_span_class;
296 }
297
303 public function setHeaderIcon($a_headericon)
304 {
305 $this->headericon = $a_headericon;
306 }
307
313 public function getHeaderIcon()
314 {
315 return $this->headericon;
316 }
317
323 public function setNoJSLinkClass($a_nojslinkclass)
324 {
325 $this->nojslinkclass = $a_nojslinkclass;
326 }
327
333 public function getNoJSLinkClass()
334 {
335 return $this->nojslinkclass;
336 }
337
343 public function setItemLinkClass($a_itemlinkclass)
344 {
345 $this->itemlinkclass = $a_itemlinkclass;
346 }
347
353 public function getItemLinkClass()
354 {
355 return $this->itemlinkclass;
356 }
357
363 public function setId($a_id)
364 {
365 $this->id = $a_id;
366 }
367
373 public function getId()
374 {
375 return $this->id;
376 }
377
383 public function setUseImages($a_useimages)
384 {
385 $this->useimages = $a_useimages;
386 }
387
393 public function getUseImages()
394 {
395 return $this->useimages;
396 }
397
403 public function setAccessKey($a_val)
404 {
405 $this->access_key = $a_val;
406 }
407
413 public function getAccessKey()
414 {
415 return $this->access_key;
416 }
417
421 public function setTriggerEvent($a_val)
422 {
423 $this->trigger_event = $a_val;
424 }
425
429 public function getTriggerEvent()
430 {
432 }
433
437 public function setAutoHide($a_val)
438 {
439 $this->auto_hide = $a_val;
440 }
441
445 public function getAutoHide()
446 {
447 return $this->auto_hide;
448 }
449
460 public function setOnClickMode($a_val, $a_onclick_form_id = "")
461 {
462 $this->on_click = $a_val;
463 $this->on_click_form_id = $a_onclick_form_id;
464 }
465
471 public function getOnClickMode()
472 {
473 return $this->on_click;
474 }
475
481 public function setSelectedValue($a_val)
482 {
483 $this->selected_value = $a_val;
484 }
485
491 public function getSelectedValue()
492 {
494 }
495
502 public function setAdditionalToggleElement($a_el, $a_on)
503 {
504 $this->toggle = array("el" => $a_el, "class_on" => $a_on);
505 }
506
513 {
514 return $this->toggle;
515 }
516
522 public function setAsynch($a_val)
523 {
524 if ($a_val) {
525 include_once("./Services/YUI/classes/class.ilYuiUtil.php");
527 }
528 $this->asynch = $a_val;
529 }
530
536 public function getAsynch()
537 {
538 return $this->asynch;
539 }
540
546 public function setAsynchUrl($a_val)
547 {
548 $this->asynch_url = $a_val;
549 }
550
556 public function getAsynchUrl()
557 {
558 return $this->asynch_url;
559 }
560
564 public function setSelectCallback($a_val)
565 {
566 $this->select_callback = $a_val;
567 }
568
572 public function getSelectCallback()
573 {
574 return $this->select_callback;
575 }
576
582 public function setPullRight($a_val)
583 {
584 $this->dd_pullright = $a_val;
585 }
586
592 public function getPullRight()
593 {
594 return $this->dd_pullright;
595 }
596
600 public function getHTML($a_only_cmd_list_asynch = false)
601 {
602 $items = $this->getItems();
603
604 // do not show list, if no item is in list
605 if (count($items) == 0 && !$this->getAsynch() && $this->getGroupedList() == null) {
606 return "";
607 }
608
609 /* bootstrap made this obsolete ?!
610 include_once("./Services/YUI/classes/class.ilYuiUtil.php");
611 ilYuiUtil::initOverlay();
612 $GLOBALS["tpl"]->addJavascript("./Services/UIComponent/Overlay/js/ilOverlay.js");
613 */
614 $GLOBALS["tpl"]->addJavascript("./Services/UIComponent/AdvancedSelectionList/js/AdvancedSelectionList.js");
615
616 $tpl = new ilTemplate(
617 "tpl.adv_selection_list.html",
618 true,
619 true,
620 "Services/UIComponent/AdvancedSelectionList",
621 "DEFAULT",
622 false,
623 true
624 );
625
626 reset($items);
627
628 $cnt = 0;
629
630 if ($this->getAsynch()) {
631 $tpl->setCurrentBlock("asynch_request");
632 $tpl->setVariable("IMG_LOADER", ilUtil::getImagePath("loader.svg"));
633 $tpl->parseCurrentBlock();
634 } else {
635 if ($this->getGroupedList() != null) {
636 $tpl->setVariable("GROUPED_LIST_HTML", $this->getGroupedList()->getHTML());
637 } else {
638 foreach ($items as $item) {
639 if (isset($item["ref_id"])) {
640 $sel_arr[$item["ref_id"]] = (isset($item["title"]))
641 ? $item["title"]
642 : "";
643 }
644 $this->css_row = ($this->css_row != "tblrow1_mo")
645 ? "tblrow1_mo"
646 : "tblrow2_mo";
647
648 if ($this->getUseImages()) {
649 if ($item["img"]) {
650 $tpl->setCurrentBlock("image");
651 $tpl->setVariable("IMG_ITEM", $item["img"]);
652 $tpl->setVariable("ALT_ITEM", $item["alt"]);
653 $tpl->parseCurrentBlock();
654 } else {
655 $tpl->touchBlock("no_image");
656 }
657 }
658
659 if ($this->getOnClickMode() ==
661 $this->getItemLinkClass() != "") {
662 if ($item["frame"]) {
663 $tpl->setCurrentBlock("frame");
664 $tpl->setVariable("TARGET_ITEM", $item["frame"]);
665 $tpl->parseCurrentBlock();
666 }
667
668 if ($this->getItemLinkClass() != "") {
669 $tpl->setCurrentBlock("item_link_class");
670 $tpl->setVariable("ITEM_LINK_CLASS", $this->getItemLinkClass());
671 $tpl->parseCurrentBlock();
672 }
673
674 if (is_array($item["data"])) {
675 foreach ($item["data"] as $k => $v) {
676 $tpl->setCurrentBlock("f_data");
677 $tpl->setVariable("DATA_KEY", $k);
678 $tpl->setVariable("DATA_VAL", ilUtil::prepareFormOutput($v));
679 $tpl->parseCurrentBlock();
680 }
681 }
682
683 $tpl->setCurrentBlock("href_s");
684 $tpl->setVariable("HREF_ITEM", 'href="' . $item["link"] . '"');
685 $tpl->setVariable("ID_ITEM", $this->getId() . "_" . $item["value"]);
686 $tpl->parseCurrentBlock();
687
688 $tpl->touchBlock("href_e");
689 }
690
691 $tpl->setCurrentBlock("item");
692 if ($this->getOnClickMode() ==
694 if ($item["prevent_background_click"]) {
695 $tpl->setVariable("ONCLICK_ITEM", '');
696 } else {
697 if ($item["onclick"] == "") {
698 $tpl->setVariable(
699 "ONCLICK_ITEM",
700 'onclick="' . "return il.AdvancedSelectionList.openTarget('" . $item["link"] . "','" . $item["frame"] . "');" . '"'
701 );
702 } else {
703 $tpl->setVariable(
704 "ONCLICK_ITEM",
705 'onclick="' . "return " . $item["onclick"] . ";" . '"'
706 );
707 }
708 }
709 } elseif ($this->getOnClickMode() ==
711 $tpl->setVariable(
712 "ONCLICK_ITEM",
713 'onclick="return il.AdvancedSelectionList.submitForm(\'' . $this->getId() . '\'' .
714 ", '" . $this->form_mode["select_name"] . "','" . $item["value"] . "'," .
715 "'" . $this->on_click_form_id . "','" . $this->form_mode["button_cmd"] . "');\""
716 );
717 } elseif ($this->getOnClickMode() ==
719 $tpl->setVariable(
720 "ONCLICK_ITEM",
721 'onclick="return il.AdvancedSelectionList.selectForm(\'' . $this->getId() . '\'' .
722 ", '" . $this->form_mode["select_name"] . "','" . $item["value"] . "'," .
723 "'" . $item["title"] . "');\""
724 );
725 } elseif ($this->getOnClickMode() ==
727 $tpl->setVariable(
728 "ONCLICK_ITEM",
729 'onclick="il.AdvancedSelectionList.clickNop(\'' . $this->getId() . '\'' .
730 ", '" . $this->form_mode["select_name"] . "','" . $item["value"] . "'," .
731 "'" . $item["title"] . "');\""
732 );
733 }
734
735 $tpl->setVariable("CSS_ROW", $this->css_row);
736 if ($item["html"] == "") {
737 $tpl->setVariable("TXT_ITEM", $item["title"]);
738 } else {
739 $tpl->setVariable("TXT_ITEM", $item["html"]);
740 }
741
742 $tpl->setVariable("ID_ITEM_TR", $this->getId() . "_" . $item["value"] . "_tr");
743 if ($item["ttip"] != "") {
744 include_once("./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
746 $this->getId() . "_" . $item["value"] . "_tr",
747 $item["ttip"],
748 "",
749 $item["tt_my"],
750 $item["tt_at"],
751 $item["tt_use_htmlspecialchars"]
752 );
753 }
754
755 $tpl->parseCurrentBlock();
756
757 // add item to js object
758 $tpl->setCurrentBlock("js_item");
759 $tpl->setVariable("IT_ID", $this->getId());
760 $tpl->setVariable("IT_HID_NAME", $this->form_mode["select_name"]);
761 $tpl->setVariable("IT_HID_VAL", $item["value"]);
762 $tpl->setVariable("IT_TITLE", str_replace("'", "\\'", $item["title"]));
763 $tpl->parseCurrentBlock();
764 }
765
766 // output hidden input, if click mode is form submission
768 $tpl->setCurrentBlock("hidden_input");
769 $tpl->setVariable("HID", $this->getId());
770 $tpl->parseCurrentBlock();
771 }
772
773 // output hidden input and initialize
775 $tpl->setCurrentBlock("hidden_input");
776 $tpl->setVariable("HID", $this->getId());
777 $tpl->parseCurrentBlock();
778
779 // init hidden input with selected value
780 $tpl->setCurrentBlock("init_hidden_input");
781 $tpl->setVariable("H2ID", $this->getId());
782 $tpl->setVariable("HID_NAME", $this->form_mode["select_name"]);
783 $tpl->setVariable("HID_VALUE", $this->getSelectedValue());
784 $tpl->parseCurrentBlock();
785 }
786 }
787 }
788
789 if ($a_only_cmd_list_asynch) {
790 $tpl->touchBlock("cmd_table");
791 return $tpl->get("cmd_table");
792 }
793
794 if ($this->getGroupedList() == null) {
795 $tpl->setCurrentBlock("dd_content");
796 if ($this->getPullRight()) {
797 $tpl->setVariable("UL_CLASS", "dropdown-menu pull-right");
798 } else {
799 $tpl->setVariable("UL_CLASS", "dropdown-menu");
800 }
801 $tpl->setVariable("TABLE_ID", $this->getId());
802 $tpl->parseCurrentBlock();
803 }
804
806 $tpl->setCurrentBlock("top_img");
807 switch ($this->getHeaderIcon()) {
809 $tpl->setVariable("IMG_SPAN_STYLE", ilAdvancedSelectionListGUI::ICON_CONFIG);
810 break;
811
813 default:
814 $tpl->setVariable("IMG_SPAN_STYLE", ilAdvancedSelectionListGUI::ICON_ARROW);
815 break;
816 }
817 $tpl->parseCurrentBlock();
818 }
819
820
821 if ($this->getAsynch()) {
822 $tpl->setCurrentBlock("asynch_bl");
823 $tpl->setVariable("ASYNCH_URL", $this->getAsynchUrl());
824 $tpl->setVariable("ASYNCH_ID", $this->getId());
825 $tpl->setVariable("ASYNCH_TRIGGER_ID", $this->getId());
826 $tpl->parseCurrentBlock();
827 }
828
829 // js section
830 $tpl->setCurrentBlock("js_section");
831 if ($this->getAccessKey() > 0) {
832 include_once("./Services/Accessibility/classes/class.ilAccessKeyGUI.php");
833 $tpl->setVariable("ACCKEY", ilAccessKeyGUI::getAttribute($this->getAccessKey()));
834 }
835
836 $cfg["trigger_event"] = $this->getTriggerEvent();
837 $cfg["auto_hide"] = $this->getAutoHide();
838
839 if ($this->getSelectCallback() != "") {
840 $cfg["select_callback"] = $this->getSelectCallback();
841 }
842 $cfg["anchor_id"] = "ilAdvSelListAnchorElement_" . $this->getId();
843 $cfg["asynch"] = $this->getAsynch()
844 ? true
845 : false;
846 $cfg["asynch_url"] = $this->getAsynchUrl();
848 if (is_array($toggle)) {
849 $cfg["toggle_el"] = $toggle["el"];
850 $cfg["toggle_class_on"] = $toggle["class_on"];
851 }
852 //echo "<br>".htmlentities($this->getAsynchUrl());
853 include_once("./Services/JSON/classes/class.ilJsonUtil.php");
854 $tpl->setVariable("CFG", ilJsonUtil::encode($cfg));
855
856 //echo htmlentities(ilJsonUtil::encode($cfg));
857
858 $tpl->setVariable("TXT_SEL_TOP", $this->getListTitle());
859 if ($this->getListTitle() == "" || $this->getAriaListTitle() != "") {
860 $aria_title = ($this->getAriaListTitle() != "")
861 ? $this->getAriaListTitle() != ""
862 : $this->lng->txt("actions");
863 $tpl->setVariable("TXT_ARIA_TOP", $aria_title);
864 }
865 $tpl->setVariable("ID", $this->getId());
866
867 //$tpl->setVariable("CLASS_SEL_TOP", $this->getSelectionHeaderClass());
868 switch ($this->getStyle()) {
870 $tpl->setVariable("BTN_CLASS", "btn btn-default");
871 $tpl->setVariable("TAG", "button");
872 break;
873
874 case self::STYLE_EMPH:
875 $tpl->setVariable("BTN_CLASS", "btn btn-primary");
876 $tpl->setVariable("TAG", "button");
877 break;
878
880 $tpl->setVariable("BTN_CLASS", "btn btn-link");
881 $tpl->setVariable("TAG", "button");
882 break;
883
884 case self::STYLE_LINK:
885 $tpl->setVariable("BTN_CLASS", "");
886 $tpl->setVariable("TAG", "a");
887 break;
888 }
889
890
891 if ($this->getSelectionHeaderSpanClass() != "") {
892 $tpl->setVariable(
893 "CLASS_SEL_TOP_SPAN",
895 );
896 }
897
898 // set the async url to an extra template variable
899 // (needed for a mobile skin)
900 // $tpl->setVariable("ASYNC_URL", $this->getAsynchUrl());
901
902 $tpl->parseCurrentBlock();
903
904 return $tpl->get();
905 }
906}
$tpl
Definition: ilias.php:10
An exception for terminatinating execution or to throw for unit testing.
static getAttribute($a_func_id)
Get accesskey HTML attribute.
User interface class for advanced drop-down selection lists.
setItemLinkClass($a_itemlinkclass)
Set Item Link Class.
setLinksMode($a_link_class="")
Set links mode (for no js fallback)
setAdditionalToggleElement($a_el, $a_on)
Set additional toggle element.
getAdditionalToggleElement()
Get additional toggle element.
setOnClickMode($a_val, $a_onclick_form_id="")
Set "onClick"- Mode.
setSelectionHeaderClass($a_selectionheaderclass)
Set Selection Header Class.
getSelectionHeaderClass()
Get Selection Header Class.
setUseImages($a_useimages)
Set Use Images.
getHTML($a_only_cmd_list_asynch=false)
Get selection list HTML.
setSelectionHeaderSpanClass($a_val)
Set selection header span class.
addItem( $a_title, $a_value="", $a_link="", $a_img="", $a_alt="", $a_frame="", $a_html="", $a_prevent_background_click=false, $a_onclick="", $a_ttip="", $a_tt_my="right center", $a_tt_at="left center", $a_tt_use_htmlspecialchars=true, $a_data=array())
Add an item.
setAsynch($a_val)
Set asynch mode (this is set to true, if list should get items asynchronously)
getNoJSLinkClass()
Get No Javascript Link Style Class.
getSelectionHeaderSpanClass()
Get selection header span class.
setAriaListTitle($a_listtitle)
Set List Title.
setNoJSLinkClass($a_nojslinkclass)
Set No Javascript Link Style Class.
setFormSelectMode( $a_select_name, $a_select_class="", $a_include_form_tag=false, $a_form_action="", $a_form_id="", $a_form_class="", $a_form_target="_top", $a_button_text="", $a_button_class="", $a_button_cmd="")
Set form mode (for no js fallback)
setHeaderIcon($a_headericon)
Set Header Icon.
setListTitle($a_listtitle)
Set List Title.
setSelectCallback($a_val)
Set select callback.
static encode($mixed, $suppress_native=false)
special template class to simplify handling of ITX/PEAR
static addTooltip( $a_el_id, $a_text, $a_container="", $a_my="bottom center", $a_at="top center", $a_use_htmlspecialchars=true)
Adds a tooltip to an HTML element.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
static initConnection(ilTemplate $a_main_tpl=null)
Init YUI Connection module.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $DIC
Definition: saml.php:7
catch(Exception $e) if(isset( $_POST[ 'cancel'])) if(isset($_POST['continue'])) $cfg