modalassociation.php
3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/**
* @package Joomla.Administrator
* @subpackage com_associations
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('JPATH_BASE') or die;
/**
* Supports a modal item picker.
*
* @since 3.7.0
*/
class JFormFieldModalAssociation extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 3.7.0
*/
protected $type = 'Modal_Association';
/**
* Method to get the field input markup.
*
* @return string The field input markup.
*
* @since 3.7.0
*/
protected function getInput()
{
// The active item id field.
$value = (int) $this->value > 0 ? (int) $this->value : '';
// Build the script.
$script = array();
// Select button script
$script[] = 'function jSelectAssociation_' . $this->id . '(id) {';
$script[] = ' target = document.getElementById("target-association");';
$script[] = ' document.getElementById("target-association").src = target.getAttribute("data-editurl") + '
. '"&task=" + target.getAttribute("data-item") + ".edit" + "&id=" + id';
$script[] = ' jQuery("#associationSelect' . $this->id . 'Modal").modal("hide");';
$script[] = '}';
// Add the script to the document head.
JFactory::getDocument()->addScriptDeclaration(implode("\n", $script));
// Setup variables for display.
$html = array();
$linkAssociations = 'index.php?option=com_associations&view=associations&layout=modal&tmpl=component'
. '&forcedItemType=' . JFactory::getApplication()->input->get('itemtype', '', 'string') . '&function=jSelectAssociation_' . $this->id;
$linkAssociations .= "&forcedLanguage=' + document.getElementById('target-association').getAttribute('data-language') + '";
$urlSelect = $linkAssociations . '&' . JSession::getFormToken() . '=1';
// Select custom association button
$html[] = '<button'
. ' type="button"'
. ' id="select-change"'
. ' class="btn' . ($value ? '' : ' hidden') . '"'
. ' data-toggle="modal"'
. ' data-select="' . JText::_('COM_ASSOCIATIONS_SELECT_TARGET') . '"'
. ' data-change="' . JText::_('COM_ASSOCIATIONS_CHANGE_TARGET') . '"'
. ' data-target="#associationSelect' . $this->id . 'Modal">'
. '<span class="icon-file" aria-hidden="true"></span>'
. '<span id="select-change-text"></span>'
. '</button>';
// Clear association button
$html[] = '<button'
. ' type="button"'
. ' class="btn' . ($value ? '' : ' hidden') . '"'
. ' onclick="return Joomla.submitbutton(\'undo-association\');"'
. ' id="remove-assoc">'
. '<span class="icon-remove" aria-hidden="true"></span>' . JText::_('JCLEAR')
. '</button>';
$html[] = '<input type="hidden" id="' . $this->id . '_id" name="' . $this->name . '" value="' . $value . '" />';
// Select custom association modal
$html[] = JHtml::_(
'bootstrap.renderModal',
'associationSelect' . $this->id . 'Modal',
array(
'title' => JText::_('COM_ASSOCIATIONS_SELECT_TARGET'),
'backdrop' => 'static',
'url' => $urlSelect,
'height' => '400px',
'width' => '800px',
'bodyHeight' => '70',
'modalWidth' => '80',
'footer' => '<button type="button" class="btn" data-dismiss="modal">'
. JText::_("JLIB_HTML_BEHAVIOR_CLOSE") . '</button>',
)
);
return implode("\n", $html);
}
}