modal-fields-uncompressed.js
6.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
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
189
190
191
192
193
194
195
196
197
198
199
/**
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
(function() {
"use strict";
/**
* Process modal fields in parent.
*
* @param string fieldPrefix The fields to be updated prefix.
* @param string id The new id for the item.
* @param string title The new title for the item.
* @param string catid Future usage.
* @param object object Future usage.
* @param string url Future usage.
* @param string language Future usage.
*
* @return boolean
*
* @since 3.7.0
*/
window.processModalParent = function (fieldPrefix, id, title, catid, url, language, object)
{
var fieldId = document.getElementById(fieldPrefix + '_id'), fieldTitle = document.getElementById(fieldPrefix + '_name');
// Default values.
id = id || '';
title = title || '';
catid = catid || '';
object = object || '';
url = url || '';
language = language || '';
if (id)
{
fieldId.value = id;
fieldTitle.value = title;
if (document.getElementById(fieldPrefix + '_select'))
{
jQuery('#' + fieldPrefix + '_select').addClass('hidden');
}
if (document.getElementById(fieldPrefix + '_new'))
{
jQuery('#' + fieldPrefix + '_new').addClass('hidden');
}
if (document.getElementById(fieldPrefix + '_edit'))
{
jQuery('#' + fieldPrefix + '_edit').removeClass('hidden');
}
if (document.getElementById(fieldPrefix + '_clear'))
{
jQuery('#' + fieldPrefix + '_clear').removeClass('hidden');
}
if (document.getElementById(fieldPrefix + '_propagate'))
{
jQuery('#' + fieldPrefix + '_propagate').removeClass('hidden');
}
}
else
{
fieldId.value = '';
fieldTitle.value = fieldId.getAttribute('data-text');
if (document.getElementById(fieldPrefix + '_select'))
{
jQuery('#' + fieldPrefix + '_select').removeClass('hidden');
}
if (document.getElementById(fieldPrefix + '_new'))
{
jQuery('#' + fieldPrefix + '_new').removeClass('hidden');
}
if (document.getElementById(fieldPrefix + '_edit'))
{
jQuery('#' + fieldPrefix + '_edit').addClass('hidden');
}
if (document.getElementById(fieldPrefix + '_clear'))
{
jQuery('#' + fieldPrefix + '_clear').addClass('hidden');
}
if (document.getElementById(fieldPrefix + '_propagate'))
{
jQuery('#' + fieldPrefix + '_propagate').addClass('hidden');
}
}
if (fieldId.getAttribute('data-required') == '1')
{
document.formvalidator.validate(fieldId);
document.formvalidator.validate(fieldTitle);
}
return false;
}
/**
* Process new/edit modal fields in child.
*
* @param object element The modal footer button element.
* @param string fieldPrefix The fields to be updated prefix.
* @param string action Modal action (add, edit).
* @param string itemType The item type (Article, Contact, etc).
* @param string task Task to be done (apply, save, cancel).
* @param string formId Id of the form field (defaults to itemtype-form).
* @param string idFieldId Id of the id field (defaults to jform_id).
* @param string titleFieldId Id of the title field (defaults to jform_title).
*
* @return boolean
*
* @since 3.7.0
*/
window.processModalEdit = function (element, fieldPrefix, action, itemType, task, formId, idFieldId, titleFieldId)
{
formId = formId || itemType.toLowerCase() + '-form';
idFieldId = idFieldId || 'jform_id';
titleFieldId = titleFieldId || 'jform_title';
var modalId = element.parentNode.parentNode.id, submittedTask = task;
// Set frame id.
jQuery('#' + modalId + ' iframe').get(0).id = 'Frame_' + modalId;
var iframeDocument = jQuery('#Frame_' + modalId).contents().get(0);
// If Close (cancel task), close the modal.
if (task === 'cancel')
{
// Submit button on child iframe so we can check out.
document.getElementById('Frame_' + modalId).contentWindow.Joomla.submitbutton(itemType.toLowerCase() + '.' + task);
jQuery('#' + modalId).modal('hide');
}
// For Save (apply task) and Save & Close (save task).
else
{
// Attach onload event to the iframe.
jQuery('#Frame_' + modalId).on('load', function()
{
// Reload iframe document var value.
iframeDocument = jQuery(this).contents().get(0);
// Validate the child form and update parent form.
if (iframeDocument.getElementById(idFieldId) && iframeDocument.getElementById(idFieldId).value != '0')
{
window.processModalParent(fieldPrefix, iframeDocument.getElementById(idFieldId).value, iframeDocument.getElementById(titleFieldId).value);
// If Save & Close (save task), submit the edit close action (so we don't have checked out items).
if (task === 'save')
{
window.processModalEdit(element, fieldPrefix, 'edit', itemType, 'cancel', formId, idFieldId, titleFieldId);
}
}
// Show the iframe again for future modals or in case of error.
jQuery('#' + modalId + ' iframe').removeClass('hidden');
});
// Submit button on child iframe.
if (iframeDocument.formvalidator.isValid(iframeDocument.getElementById(formId)))
{
// For Save & Close (save task) when creating we need to replace the task as apply because of redirects after submit and hide the iframe.
if (task === 'save')
{
submittedTask = 'apply';
}
document.getElementById('Frame_' + modalId).contentWindow.Joomla.submitbutton(itemType.toLowerCase() + '.' + submittedTask);
}
}
return false;
}
/**
* Process select modal fields in child.
*
* @param string itemType The item type (Article, Contact, etc).
* @param string fieldPrefix The fields to be updated prefix.
* @param string id The new id for the item.
* @param string title The new title for the item.
* @param string catid Future usage.
* @param object object Future usage.
* @param string url Future usage.
* @param string language Future usage.
*
* @return boolean
*
* @since 3.7.0
*/
window.processModalSelect = function(itemType, fieldPrefix, id, title, catid, object, url, language) {
window.processModalParent(fieldPrefix, id, title, catid, url, language, object);
jQuery('#ModalSelect' + itemType + '_' + fieldPrefix).modal('hide');
return false;
}
}());