|
1
2
|
/* global $dj, getBusyOverlay */
|
|
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
var tt_id, busy_ctrl;
function busy_on() {
"use strict";
busy_ctrl = getBusyOverlay(
$('#table-edit')[0],
{color: 'black', opacity: 0.2},
{size: 30});
}
function busy_off() {
"use strict";
if (busy_ctrl) busy_ctrl.remove();
busy_ctrl = null;
}
|
|
18
19
20
|
function template_form_init() {
"use strict";
|
|
21
22
23
|
var edit_form = $('#template-edit-form');
edit_form.find('button').button();
edit_form.find('select[multiple]').multiSelect({
|
|
24
|
minWidth: 120,
|
|
25
|
selectedList: 3
|
|
26
|
});
|
|
27
|
busy_off();
|
|
28
29
30
31
32
|
}
function load_template() {
"use strict";
tt_id = parseInt($('#id_table_template').val(), 10);
|
|
33
|
busy_on();
|
|
34
35
36
37
38
|
$.ajaxJSON({
method: 'get',
url: $dj.ajax_load_template,
data: {template_id: tt_id},
dest: $('#template-edit-form'),
|
|
39
40
|
callback: template_form_init,
error_callback: busy_off
|
|
41
42
43
44
45
46
47
48
49
50
51
|
});
$.ajaxJSON({
method: 'get',
url: $dj.ajax_preview_form,
data: {template_id: tt_id},
dest: $('#template-preview')
});
}
function load_preview() {
"use strict";
|
|
52
|
var form = $('#preview-params');
|
|
53
|
var attr_data = form.find('.closed-attr').map(function(i, elem) {
|
|
54
55
|
return $(elem).val();
}).toArray();
|
|
56
57
58
59
60
|
$.ajaxJSON({
method: 'get',
url: $dj.ajax_load_preview,
data: {
template_id: tt_id,
|
|
61
62
63
|
pattern_type_id: form.find('.pattern-type-select').val(),
gender_id: form.find('.gender-select').val() || null,
attr_data: attr_data
|
|
64
65
66
67
68
|
},
dest: $('#preview-table')
});
}
|
|
69
70
71
72
73
74
75
76
|
function save_template() {
"use strict";
var table_cells = [], export_cells = [], headers = [];
busy_on();
$('#template-edit-form').find('tr').each(function(i, elem) {
var $e = $(elem);
if ($e.find('select').length === 0)
return;
|
|
77
78
|
var row, col, rspan, cspan, index, bfl, prefix, suffix, pts, tag,
label, css_class, attr_vals, genders;
|
|
79
80
81
82
83
84
85
86
|
row = $e.find('.row').val();
col = $e.find('.col').val();
rspan = $e.find('.rspan').val();
cspan = $e.find('.cspan').val();
bfl = $e.find('.bfl-select').val();
prefix = $e.find('.pre').val();
suffix = $e.find('.suf').val();
pts = $e.find('.pattern-types-select').val();
|
|
87
|
genders = $e.find('.gender-select').val();
|
|
88
89
90
|
attr_vals = $e.find('.attrs-select').map(function(i, elem) {
return $(elem).val();
}).toArray();
|
|
91
92
93
|
if ($e.hasClass('table')) {
index = $e.find('.ind').val();
table_cells.push(
|
|
94
95
|
[row, col, rspan, cspan, index, bfl, prefix, suffix, pts,
genders, attr_vals]);
|
|
96
97
98
99
|
} else if ($e.hasClass('header')) {
label = $e.find('.label').val();
css_class = $e.find('.css-class-select').val();
headers.push(
|
|
100
101
|
[row, col, rspan, cspan, label, css_class, pts,
genders, attr_vals]);
|
|
102
103
104
|
} else if ($e.hasClass('export')) {
tag = $e.find('.tag').val();
export_cells.push(
|
|
105
|
[bfl, prefix, suffix, tag, pts, genders, attr_vals]);
|
|
106
107
108
109
110
111
112
113
114
115
116
117
118
|
}
});
$.ajaxJSON({
method: 'post',
url: $dj.ajax_save_template,
data: {
template_id: tt_id,
table_cells: table_cells,
headers: headers,
export_cells: export_cells
},
callback: function() {
busy_off();
|
|
119
120
121
|
},
error_callback: function() {
busy_off();
|
|
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
}
});
}
var new_row_counter = 1;
function add_row(type) {
"use strict";
$.ajaxJSON({
method: 'get',
url: $dj.ajax_template_row,
data: {
template_id: tt_id,
row_type: type,
num: new_row_counter
},
callback: function(data) {
var new_row = $(data.html);
$('#template-edit-form').find('thead').after(new_row);
|
|
140
141
|
new_row.find('select[multiple]').multiSelect({
minWidth: 120,
|
|
142
|
selectedList: 3
|
|
143
|
});
|
|
144
145
146
147
148
|
}
});
new_row_counter++;
}
|
|
149
150
151
|
$(function() {
"use strict";
$('#load-template').click(load_template);
|
|
152
|
$(document).on('click', '#cancel', load_template);
|
|
153
|
$(document).on('click', '#load-preview', load_preview);
|
|
154
155
156
157
158
159
160
161
162
163
164
165
166
|
$(document).on('click', '#save-template', save_template);
$(document).on('click', '.remove', function() {
$(this).closest('tr').remove();
});
$(document).on('click', '#add-table-cell', function() {
add_row('table');
});
$(document).on('click', '#add-header', function() {
add_row('header');
});
$(document).on('click', '#add-export-cell', function() {
add_row('export');
});
|
|
167
|
});
|