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
|
# File 'app/helpers/admin/pages_helper.rb', line 25
def page_edit_javascripts
<<-CODE
function addPart(form) {
if (validPartName()) {
new Ajax.Updater(
$('tab_control').down('.pages'),
'#{admin_page_parts_path}',
{
asynchronous: true,
evalScripts: true,
insertion: 'bottom',
onComplete: function(request){ partAdded() },
onLoading: function(request){ partLoading() },
parameters: Form.serialize(form)
}
);
}
}
function removePart() {
if(confirm('Remove the current part?')) {
TabControls['tab_control'].removeSelected();
}
}
function partAdded() {
var tabControl = TabControls['tab_control'];
$('add_part_busy').hide();
$('add_part_button').disabled = false;
$('add_part_popup').closePopup();
$('part_name_field').value = '';
tabControl.updateTabs();
tabControl.select(tabControl.tabs.last());
}
function partLoading() {
$('add_part_button').disabled = true;
$('add_part_busy').appear();
}
function validPartName() {
var partNameField = $('part_name_field');
var name = partNameField.value.downcase();
if (name.blank()) {
alert('Part name cannot be empty.');
return false;
}
if (TabControls['tab_control'].findTabByCaption(name)) {
alert('Part name must be unique.');
return false;
}
return true;
}
var lastPageType = '#{@page.class.name}';
var tagReferenceWindows = {};
function loadTagReference(part) {
var pageType = $F('page_class_name');
if (!tagReferenceWindows[pageType])
tagReferenceWindows[pageType] = new Popup.AjaxWindow("/admin/references/tags?class_name=" + encodeURIComponent(pageType), {reload: false});
var window = tagReferenceWindows[pageType];
if(lastPageType != pageType) {
$('tag_reference_link_' + part).highlight();
window.show();
} else {
window.toggle();
}
lastPageType = pageType;
return false;
}
var lastFilter = '#{default_filter_name}';
var filterWindows = {};
function loadFilterReference(part) {
var filter = $F("part_" + part + "_filter_id");
if (filter != "") {
if (!filterWindows[filter]) filterWindows[filter] = new Popup.AjaxWindow("/admin/references/filters?filter_name="+encodeURIComponent(filter), {reload: false});
var window = filterWindows[filter];
if(lastFilter != filter) {
window.show();
} else {
window.toggle();
}
lastFilter = filter;
} else {
alert('No documentation for filter.');
}
return false;
}
CODE
end
|