view.html.php
6.03 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
// namespace administrator\components\com_jmap\views\datasets;
/**
* @package JMAP::DATASETS::administrator::components::com_jmap
* @subpackage views
* @subpackage datasets
* @author Joomla! Extensions Store
* @copyright (C) 2015 - Joomla! Extensions Store
* @license GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html
*/
defined ( '_JEXEC' ) or die ( 'Restricted access' );
/**
* @package JMAP::DATASETS::administrator::components::com_jmap
* @subpackage views
* @subpackage datasets
* @since 2.0
*/
class JMapViewDatasets extends JMapView {
/**
* Add the page title and toolbar.
*
* @since 1.6
*/
protected function addEditEntityToolbar() {
$user = JFactory::getUser();
$userId = $user->get('id');
$isNew = ($this->record->id == 0);
$checkedOut = !($this->record->checked_out == 0 || $this->record->checked_out == $userId);
$toolbarHelperTitle = $isNew ? 'COM_JMAP_DATASETS_NEW' : 'COM_JMAP_DATASETS_EDIT';
$doc = JFactory::getDocument();
$doc->addStyleDeclaration('.icon-48-jmap{background-image:url("components/com_jmap/images/icon-48-datasets.png")}');
JToolBarHelper::title( JText::_( $toolbarHelperTitle ), 'jmap' );
if ($isNew) {
// For new records, check the create permission.
if ($isNew && ($user->authorise('core.create', 'com_jmap'))) {
JToolBarHelper::apply( 'datasets.applyEntity', 'JAPPLY');
JToolBarHelper::save( 'datasets.saveEntity', 'JSAVE');
JToolBarHelper::save2new( 'datasets.saveEntity2New');
}
} else {
// Can't save the record if it's checked out.
if (!$checkedOut) {
// Since it's an existing record, check the edit permission, or fall back to edit own if the owner.
if ($user->authorise('core.edit', 'com_jmap')) {
JToolBarHelper::apply( 'datasets.applyEntity', 'JAPPLY');
JToolBarHelper::save( 'datasets.saveEntity', 'JSAVE');
JToolBarHelper::save2new( 'datasets.saveEntity2New');
}
}
}
JToolBarHelper::custom('datasets.cancelEntity', 'cancel', 'cancel', 'JCANCEL', false);
}
/**
* Add the page title and toolbar.
*
* @since 1.6
*/
protected function addDisplayToolbar() {
$doc = JFactory::getDocument();
$doc->addStyleDeclaration('.icon-48-jmap{background-image:url("components/com_jmap/images/icon-48-datasets.png")}');
$user = JFactory::getUser();
JToolBarHelper::title( JText::_('COM_JMAP_DATASETS' ), 'jmap' );
// Access check.
if ($user->authorise('core.create', 'com_jmap')) {
JToolBarHelper::addNew('datasets.editentity', 'COM_JMAP_NEW_DATASET');
}
if ($user->authorise('core.edit', 'com_jmap')) {
JToolBarHelper::editList('datasets.editentity', 'COM_JMAP_EDIT_DATASET');
}
if ($user->authorise('core.delete', 'com_jmap') && $user->authorise('core.edit', 'com_jmap')) {
JToolBarHelper::deleteList('COM_JMAP_DELETE_LINK', 'datasets.deleteentity');
}
JToolBarHelper::custom('cpanel.display', 'home', 'home', 'COM_JMAP_CPANEL', false);
}
/**
* Default display listEntities
*
* @access public
* @param string $tpl
* @return void
*/
public function display($tpl = null) {
// Get main records
$rows = $this->get ( 'Data' );
$total = $this->get ( 'Total' );
$doc = JFactory::getDocument();
$this->loadJQuery($doc);
$this->loadBootstrap($doc);
$doc->addStylesheet ( JUri::root ( true ) . '/administrator/components/com_jmap/css/datasets.css' );
$orders = array ();
$orders ['order'] = $this->getModel ()->getState ( 'order' );
$orders ['order_Dir'] = $this->getModel ()->getState ( 'order_dir' );
// Pagination view object model state populated
$pagination = new JPagination ( $total, $this->getModel ()->getState ( 'limitstart' ), $this->getModel ()->getState ( 'limit' ) );
$this->user = JFactory::getUser ();
$this->pagination = $pagination;
$this->searchword = $this->getModel ()->getState ( 'searchword' );
$this->orders = $orders;
$this->items = $rows;
$this->option = $this->getModel ()->getState ( 'option' );
// Aggiunta toolbar
$this->addDisplayToolbar();
parent::display ( 'list' );
}
/**
* Edit entity view
*
* @access public
* @param Object& $row the item to edit
* @return void
*/
public function editEntity(&$row) {
// Sanitize HTML Object2Form
JFilterOutput::objectHTMLSafe( $row );
// Detect uri scheme
$instance = JUri::getInstance();
$this->urischeme = $instance->isSSL() ? 'https' : 'http';
// Load JS Client App dependencies
$doc = JFactory::getDocument();
$base = JUri::root();
$this->loadJQuery($doc);
$this->loadJQueryUI($doc);
$this->loadBootstrap($doc);
$this->loadValidation($doc);
$doc->addStylesheet ( JUri::root ( true ) . '/administrator/components/com_jmap/css/datasets.css' );
$doc->addScriptDeclaration("var jmap_baseURI='$base';");
$doc->addScriptDeclaration("var jmap_urischeme='$this->urischeme';");
// Inject js translations
$translations = array( 'COM_JMAP_SELECTONESOURCE' );
$this->injectJsTranslations($translations, $doc);
// Load specific JS App
$doc->addScript ( JUri::root ( true ) . '/administrator/components/com_jmap/js/jquery.form.min.js' );
$doc->addScript ( JUri::root ( true ) . '/administrator/components/com_jmap/js/datasets.js' );
$doc->addScriptDeclaration("
Joomla.submitbutton = function(pressbutton) {
if(!jQuery.fn.validation) {
jQuery.extend(jQuery.fn, jmapjQueryBackup.fn);
}
jQuery('#adminForm').validation();
if (pressbutton == 'datasets.cancelEntity') {
jQuery('#adminForm').off();
Joomla.submitform( pressbutton );
return true;
}
if(jQuery('#adminForm').validate() && JMapDatasets.validateSelectable()) {
Joomla.submitform( pressbutton );
return true;
}
return false;
};
");
$lists = $this->getModel()->getLists($row);
$this->option = $this->getModel ()->getState ( 'option' );
$this->componentParams = $this->getModel()->getComponentParams();
$this->record = $row;
$this->lists = $lists;
// Aggiunta toolbar
$this->addEditEntityToolbar();
parent::display ( 'edit' );
}
}