ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 if ($item["value"] != "") {
683 $tpl->setCurrentBlock("item_id");
684 $tpl->setVariable("ID_ITEM", $this->getId() . "_" . $item["value"]);
685 $tpl->parseCurrentBlock();
686 }
687
688 $tpl->setCurrentBlock("href_s");
689 $tpl->setVariable("HREF_ITEM", 'href="' . $item["link"] . '"');
690 $tpl->parseCurrentBlock();
691
692 $tpl->touchBlock("href_e");
693 }
694
695 $tpl->setCurrentBlock("item");
696 if ($this->getOnClickMode() ==
698 if ($item["prevent_background_click"]) {
699 $tpl->setVariable("ONCLICK_ITEM", '');
700 } else {
701 if ($item["onclick"] == "") {
702 $tpl->setVariable(
703 "ONCLICK_ITEM",
704 'onclick="' . "return il.AdvancedSelectionList.openTarget('" . $item["link"] . "','" . $item["frame"] . "');" . '"'
705 );
706 } else {
707 $tpl->setVariable(
708 "ONCLICK_ITEM",
709 'onclick="' . "return " . $item["onclick"] . ";" . '"'
710 );
711 }
712 }
713 } elseif ($this->getOnClickMode() ==
715 $tpl->setVariable(
716 "ONCLICK_ITEM",
717 'onclick="return il.AdvancedSelectionList.submitForm(\'' . $this->getId() . '\'' .
718 ", '" . $this->form_mode["select_name"] . "','" . $item["value"] . "'," .
719 "'" . $this->on_click_form_id . "','" . $this->form_mode["button_cmd"] . "');\""
720 );
721 } elseif ($this->getOnClickMode() ==
723 $tpl->setVariable(
724 "ONCLICK_ITEM",
725 'onclick="return il.AdvancedSelectionList.selectForm(\'' . $this->getId() . '\'' .
726 ", '" . $this->form_mode["select_name"] . "','" . $item["value"] . "'," .
727 "'" . $item["title"] . "');\""
728 );
729 } elseif ($this->getOnClickMode() ==
731 $tpl->setVariable(
732 "ONCLICK_ITEM",
733 'onclick="il.AdvancedSelectionList.clickNop(\'' . $this->getId() . '\'' .
734 ", '" . $this->form_mode["select_name"] . "','" . $item["value"] . "'," .
735 "'" . $item["title"] . "');\""
736 );
737 }
738
739 $tpl->setVariable("CSS_ROW", $this->css_row);
740 if ($item["html"] == "") {
741 $tpl->setVariable("TXT_ITEM", $item["title"]);
742 } else {
743 $tpl->setVariable("TXT_ITEM", $item["html"]);
744 }
745
746 $tpl->setVariable("ID_ITEM_TR", $this->getId() . "_" . $item["value"] . "_tr");
747 if ($item["ttip"] != "") {
748 include_once("./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
750 $this->getId() . "_" . $item["value"] . "_tr",
751 $item["ttip"],
752 "",
753 $item["tt_my"],
754 $item["tt_at"],
755 $item["tt_use_htmlspecialchars"]
756 );
757 }
758
759 $tpl->parseCurrentBlock();
760
761 // add item to js object
762 $tpl->setCurrentBlock("js_item");
763 $tpl->setVariable("IT_ID", $this->getId());
764 $tpl->setVariable("IT_HID_NAME", $this->form_mode["select_name"]);
765 $tpl->setVariable("IT_HID_VAL", $item["value"]);
766 $tpl->setVariable("IT_TITLE", str_replace("'", "\\'", $item["title"]));
767 $tpl->parseCurrentBlock();
768 }
769
770 // output hidden input, if click mode is form submission
772 $tpl->setCurrentBlock("hidden_input");
773 $tpl->setVariable("HID", $this->getId());
774 $tpl->parseCurrentBlock();
775 }
776
777 // output hidden input and initialize
779 $tpl->setCurrentBlock("hidden_input");
780 $tpl->setVariable("HID", $this->getId());
781 $tpl->parseCurrentBlock();
782
783 // init hidden input with selected value
784 $tpl->setCurrentBlock("init_hidden_input");
785 $tpl->setVariable("H2ID", $this->getId());
786 $tpl->setVariable("HID_NAME", $this->form_mode["select_name"]);
787 $tpl->setVariable("HID_VALUE", $this->getSelectedValue());
788 $tpl->parseCurrentBlock();
789 }
790 }
791 }
792
793 if ($a_only_cmd_list_asynch) {
794 $tpl->touchBlock("cmd_table");
795 return $tpl->get("cmd_table");
796 }
797
798 if ($this->getGroupedList() == null) {
799 $tpl->setCurrentBlock("dd_content");
800 if ($this->getPullRight()) {
801 $tpl->setVariable("UL_CLASS", "dropdown-menu pull-right");
802 } else {
803 $tpl->setVariable("UL_CLASS", "dropdown-menu");
804 }
805 $tpl->setVariable("TABLE_ID", $this->getId());
806 $tpl->parseCurrentBlock();
807 }
808
810 $tpl->setCurrentBlock("top_img");
811 switch ($this->getHeaderIcon()) {
813 $tpl->setVariable("IMG_SPAN_STYLE", ilAdvancedSelectionListGUI::ICON_CONFIG);
814 break;
815
817 default:
818 $tpl->setVariable("IMG_SPAN_STYLE", ilAdvancedSelectionListGUI::ICON_ARROW);
819 break;
820 }
821 $tpl->parseCurrentBlock();
822 }
823
824
825 if ($this->getAsynch()) {
826 $tpl->setCurrentBlock("asynch_bl");
827 $tpl->setVariable("ASYNCH_URL", $this->getAsynchUrl());
828 $tpl->setVariable("ASYNCH_ID", $this->getId());
829 $tpl->setVariable("ASYNCH_TRIGGER_ID", $this->getId());
830 $tpl->parseCurrentBlock();
831 }
832
833 // js section
834 $tpl->setCurrentBlock("js_section");
835 if ($this->getAccessKey() > 0) {
836 include_once("./Services/Accessibility/classes/class.ilAccessKeyGUI.php");
837 $tpl->setVariable("ACCKEY", ilAccessKeyGUI::getAttribute($this->getAccessKey()));
838 }
839
840 $cfg["trigger_event"] = $this->getTriggerEvent();
841 $cfg["auto_hide"] = $this->getAutoHide();
842
843 if ($this->getSelectCallback() != "") {
844 $cfg["select_callback"] = $this->getSelectCallback();
845 }
846 $cfg["anchor_id"] = "ilAdvSelListAnchorElement_" . $this->getId();
847 $cfg["asynch"] = $this->getAsynch()
848 ? true
849 : false;
850 $cfg["asynch_url"] = $this->getAsynchUrl();
852 if (is_array($toggle)) {
853 $cfg["toggle_el"] = $toggle["el"];
854 $cfg["toggle_class_on"] = $toggle["class_on"];
855 }
856 //echo "<br>".htmlentities($this->getAsynchUrl());
857 include_once("./Services/JSON/classes/class.ilJsonUtil.php");
858 $tpl->setVariable("CFG", ilJsonUtil::encode($cfg));
859
860 //echo htmlentities(ilJsonUtil::encode($cfg));
861
862 $tpl->setVariable("TXT_SEL_TOP", $this->getListTitle());
863 if ($this->getListTitle() == "" || $this->getAriaListTitle() != "") {
864 $aria_title = ($this->getAriaListTitle() != "")
865 ? $this->getAriaListTitle() != ""
866 : $this->lng->txt("actions");
867 $tpl->setVariable("TXT_ARIA_TOP", $aria_title);
868 }
869 $tpl->setVariable("ID", $this->getId());
870
871 //$tpl->setVariable("CLASS_SEL_TOP", $this->getSelectionHeaderClass());
872 switch ($this->getStyle()) {
874 $tpl->setVariable("BTN_CLASS", "btn btn-default");
875 $tpl->setVariable("TAG", "button");
876 break;
877
878 case self::STYLE_EMPH:
879 $tpl->setVariable("BTN_CLASS", "btn btn-primary");
880 $tpl->setVariable("TAG", "button");
881 break;
882
884 $tpl->setVariable("BTN_CLASS", "btn btn-link");
885 $tpl->setVariable("TAG", "button");
886 break;
887
888 case self::STYLE_LINK:
889 $tpl->setVariable("BTN_CLASS", "");
890 $tpl->setVariable("TAG", "a");
891 break;
892 }
893
894
895 if ($this->getSelectionHeaderSpanClass() != "") {
896 $tpl->setVariable(
897 "CLASS_SEL_TOP_SPAN",
899 );
900 }
901
902 // set the async url to an extra template variable
903 // (needed for a mobile skin)
904 // $tpl->setVariable("ASYNC_URL", $this->getAsynchUrl());
905
906 $tpl->parseCurrentBlock();
907
908 return $tpl->get();
909 }
910}
$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['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
global $DIC
Definition: saml.php:7
catch(Exception $e) if(isset( $_POST[ 'cancel'])) if(isset($_POST['continue'])) $cfg