1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3require_once('./Modules/Cloud/classes/class.ilCloudPluginListGUI.php');
4
5/**
6 * Class ilCloudPluginActionListGUI
7 *
8 * Basic functionality of the action list. Can be extended to define addidtional actions by the plugin. Note that
9 * the list is loaded asyncronically by default. Disable if not wanted.
10 *
11 * @author  Timon Amstutz <timon.amstutz@ilub.unibe.ch>
12 * @author  Fabian Schmid <fs@studer-raimann.ch>
13 *
14 * @version $Id:
15 * @extends ilCloudPluginListGUI
16 * @ingroup ModulesCloud
17 */
18class ilCloudPluginActionListGUI extends ilCloudPluginListGUI
19{
20
21    /**
22     * @var ilAdvancedSelectionListGUI
23     */
24    protected $selection_list;
25    /**
26     * @var ilcloudFileNode
27     */
28    protected $node = null;
29
30
31    /**
32     * @param bool            $delete_item
33     * @param bool            $delete_folder
34     * @param ilCloudFileNode $node
35     *
36     * @return string
37     */
38    public function getSelectionListItemsHTML($delete_item = false, $delete_folder = false, ilCloudFileNode $node)
39    {
40        global $DIC;
41        $lng = $DIC['lng'];
42        $ilCtrl = $DIC['ilCtrl'];
43
44        /**
45         * @var ilCtrl $ilCtrl
46         */
47
48        $this->node = $node;
49
50        if (($delete_item && !$node->getIsDir()) || ($delete_folder && $node->getIsDir()) || $this->checkHasAction()) {
51            include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
52            $this->selection_list = new ilAdvancedSelectionListGUI();
53            $this->selection_list->setId("id_action_list_" . $this->node->getId());
54            $this->selection_list->setListTitle($lng->txt("actions"));
55            $this->selection_list->setItemLinkClass("xsmall");
56
57            if ($this->getAsyncMode()) {
58                $this->selection_list->setAsynch(true);
59                $this->selection_list->setAsynchUrl(html_entity_decode($ilCtrl->getLinkTargetByClass("ilobjcloudgui", "asyncGetActionListContent", false)
60                    . "&node_id=" . $node->getId()));
61            } else {
62                $this->addSelectionListItems($delete_item, $delete_folder);
63            }
64
65            return $this->selection_list->getHtml();
66        } else {
67            return "";
68        }
69    }
70
71
72    /**
73     * @param $delete_item
74     * @param $delete_folder
75     */
76    protected function addSelectionListItems($delete_item, $delete_folder)
77    {
78        global $DIC;
79        $lng = $DIC['lng'];
80        $this->addItemsBefore();
81        if (($delete_item && !$this->node->getIsDir()) || ($delete_folder && $this->node->getIsDir())) {
82            $this->selection_list->addItem($lng->txt("delete"), "delete_item", "javascript:il.CloudFileList.deleteItem('" . $this->node->getId()
83                . "');");
84        }
85
86        $this->addItemsAfter();
87    }
88
89
90    /**
91     * @param bool            $delete_item
92     * @param bool            $delete_folder
93     * @param ilCloudFileNode $node
94     */
95    public function asyncGetContent($delete_item = false, $delete_folder = false, ilCloudFileNode $node)
96    {
97        global $DIC;
98        $lng = $DIC['lng'];
99        $this->node = $node;
100        include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
101        $this->selection_list = new ilAdvancedSelectionListGUI();
102        $this->selection_list->setId($this->node->getId());
103        $this->selection_list->setListTitle($lng->txt("actions"));
104        $this->selection_list->setItemLinkClass("xsmall");
105
106        $this->addSelectionListItems($delete_item, $delete_folder);
107        if ($this->selection_list->getItems() != null) {
108            echo $this->selection_list->getHTML(true);
109            exit;
110        } else {
111            echo $lng->txt("empty");
112            exit;
113        }
114    }
115
116
117    protected function addItemsBefore()
118    {
119    }
120
121
122    protected function addItemsAfter()
123    {
124    }
125
126
127    protected function checkHasAction()
128    {
129    }
130
131
132    /**
133     * @return bool
134     */
135    protected function getAsyncMode()
136    {
137        return true;
138    }
139}
140