|
1
|
|
|
'use strict'; |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Initialises a user field with auto completion. |
|
5
|
|
|
*/ |
|
6
|
|
|
function zikulaRoutesInitUserField(fieldName, getterName) |
|
7
|
|
|
{ |
|
8
|
|
|
if (jQuery('#' + fieldName + 'LiveSearch').length < 1) { |
|
9
|
|
|
return; |
|
10
|
|
|
} |
|
11
|
|
|
jQuery('#' + fieldName + 'LiveSearch').removeClass('hidden'); |
|
12
|
|
|
|
|
13
|
|
|
jQuery('#' + fieldName + 'Selector').typeahead({ |
|
14
|
|
|
highlight: true, |
|
15
|
|
|
hint: true, |
|
16
|
|
|
minLength: 2 |
|
17
|
|
|
}, { |
|
18
|
|
|
limit: 15, |
|
19
|
|
|
// The data source to query against. Receives the query value in the input field and the process callbacks. |
|
20
|
|
|
source: function (query, syncResults, asyncResults) { |
|
21
|
|
|
// Retrieve data from server using "query" parameter as it contains the search string entered by the user |
|
22
|
|
|
jQuery('#' + fieldName + 'Indicator').removeClass('hidden'); |
|
23
|
|
|
jQuery.getJSON(Routing.generate('zikularoutesmodule_ajax_' + getterName.toLowerCase(), { fragment: query }), function( data ) { |
|
|
|
|
|
|
24
|
|
|
jQuery('#' + fieldName + 'Indicator').addClass('hidden'); |
|
25
|
|
|
asyncResults(data); |
|
26
|
|
|
}); |
|
27
|
|
|
}, |
|
28
|
|
|
templates: { |
|
29
|
|
|
empty: '<div class="empty-message">' + jQuery('#' + fieldName + 'NoResultsHint').text() + '</div>', |
|
30
|
|
|
suggestion: function(user) { |
|
31
|
|
|
var html; |
|
32
|
|
|
|
|
33
|
|
|
html = '<div class="typeahead">'; |
|
34
|
|
|
html += '<div class="media"><a class="pull-left" href="javascript:void(0)">' + user.avatar + '</a>'; |
|
35
|
|
|
html += '<div class="media-body">'; |
|
36
|
|
|
html += '<p class="media-heading">' + user.uname + '</p>'; |
|
37
|
|
|
html += '</div>'; |
|
38
|
|
|
html += '</div>'; |
|
39
|
|
|
|
|
40
|
|
|
return html; |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
}).bind('typeahead:select', function(ev, user) { |
|
44
|
|
|
// Called after the user selects an item. Here we can do something with the selection. |
|
45
|
|
|
jQuery('#' + fieldName).val(user.uid); |
|
46
|
|
|
jQuery(this).typeahead('val', user.uname); |
|
47
|
|
|
}); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
var editedObjectType; |
|
52
|
|
|
var editedEntityId; |
|
53
|
|
|
var editForm; |
|
54
|
|
|
var formButtons; |
|
55
|
|
|
var triggerValidation = true; |
|
56
|
|
|
|
|
57
|
|
|
function zikulaRoutesTriggerFormValidation() |
|
58
|
|
|
{ |
|
59
|
|
|
zikulaRoutesExecuteCustomValidationConstraints(editedObjectType, editedEntityId); |
|
60
|
|
|
|
|
61
|
|
|
if (!editForm.get(0).checkValidity()) { |
|
62
|
|
|
// This does not really submit the form, |
|
63
|
|
|
// but causes the browser to display the error message |
|
64
|
|
|
editForm.find(':submit').first().click(); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
function zikulaRoutesHandleFormSubmit (event) { |
|
69
|
|
|
if (triggerValidation) { |
|
70
|
|
|
zikulaRoutesTriggerFormValidation(); |
|
71
|
|
|
if (!editForm.get(0).checkValidity()) { |
|
72
|
|
|
event.preventDefault(); |
|
73
|
|
|
return false; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
// hide form buttons to prevent double submits by accident |
|
78
|
|
|
formButtons.each(function (index) { |
|
|
|
|
|
|
79
|
|
|
jQuery(this).addClass('hidden'); |
|
80
|
|
|
}); |
|
81
|
|
|
|
|
82
|
|
|
return true; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Initialises an entity edit form. |
|
87
|
|
|
*/ |
|
88
|
|
|
function zikulaRoutesInitEditForm(mode, entityId) |
|
89
|
|
|
{ |
|
90
|
|
|
if (jQuery('.zikularoutes-edit-form').length < 1) { |
|
91
|
|
|
return; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
editForm = jQuery('.zikularoutes-edit-form').first(); |
|
95
|
|
|
editedObjectType = editForm.attr('id').replace('EditForm', ''); |
|
96
|
|
|
editedEntityId = entityId; |
|
97
|
|
|
|
|
98
|
|
|
if (jQuery('#moderationFieldsSection').length > 0) { |
|
99
|
|
|
jQuery('#moderationFieldsContent').addClass('hidden'); |
|
100
|
|
|
jQuery('#moderationFieldsSection legend').addClass('pointer').click(function (event) { |
|
|
|
|
|
|
101
|
|
|
if (jQuery('#moderationFieldsContent').hasClass('hidden')) { |
|
102
|
|
|
jQuery('#moderationFieldsContent').removeClass('hidden'); |
|
103
|
|
|
jQuery(this).find('i').removeClass('fa-expand').addClass('fa-compress'); |
|
104
|
|
|
} else { |
|
105
|
|
|
jQuery('#moderationFieldsContent').addClass('hidden'); |
|
106
|
|
|
jQuery(this).find('i').removeClass('fa-compress').addClass('fa-expand'); |
|
107
|
|
|
} |
|
108
|
|
|
}); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
var allFormFields = editForm.find('input, select, textarea'); |
|
112
|
|
|
allFormFields.change(function (event) { |
|
|
|
|
|
|
113
|
|
|
zikulaRoutesExecuteCustomValidationConstraints(editedObjectType, editedEntityId); |
|
114
|
|
|
}); |
|
115
|
|
|
|
|
116
|
|
|
formButtons = editForm.find('.form-buttons input'); |
|
117
|
|
|
editForm.find('.btn-danger').first().bind('click keypress', function (event) { |
|
118
|
|
|
if (!window.confirm(Translator.__('Do you really want to delete this entry?'))) { |
|
|
|
|
|
|
119
|
|
|
event.preventDefault(); |
|
120
|
|
|
} |
|
121
|
|
|
}); |
|
122
|
|
|
editForm.find('button[type=submit]').bind('click keypress', function (event) { |
|
|
|
|
|
|
123
|
|
|
triggerValidation = !jQuery(this).attr('formnovalidate'); |
|
124
|
|
|
}); |
|
125
|
|
|
editForm.submit(zikulaRoutesHandleFormSubmit); |
|
126
|
|
|
|
|
127
|
|
|
if (mode != 'create') { |
|
128
|
|
|
zikulaRoutesTriggerFormValidation(); |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.