manage-vocabularies.js
7.23 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
200
201
202
203
204
205
206
/*
Copyright (c) 2012, Bartłomiej Nitoń
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
$(function() {
$('form.voc-download-form').live('submit', download_form_submit);
$('#vocabulary-select').live('change', show_vocabulary_info);
$('form.vocab-perm-manage-form').live('submit', vocab_perm_manage_form_submit);
$('#other-statistisc').load(ajax_get_other_stats);
show_vocabulary_info();
});
function vocab_perm_manage_form_submit() {
ShowProgressAnimation();
this_form = $(this);
form_data = this_form.serializeArray();
var editors = new Array();
var viewers = new Array();
form_data = $.map(form_data, function(elem)
{
if (elem.name != 'editors' && elem.name != 'viewers')
return elem;
else {
if (elem.name == 'editors')
editors.push(elem.value);
else if (elem.name == 'viewers')
viewers.push(elem.value);
}
});
form_data.push({name: 'editors', value: editors});
form_data.push({name: 'viewers', value: viewers});
form_data.push({name: 'vocabulary_name', value: $('#vocabulary-select').val()});
$.ajaxJSON({
method: 'post',
url: ajax_vocab_perm_manage_form_submit,
data: {
form_data: form_data
},
callback: function(result) {
HideProgressAnimation();
},
error_callback: function(xhr, status, error) {
HideProgressAnimation();
error_alert(status + ': ' + error);
},
bad_data_callback: function(result) {
HideProgressAnimation();
return true;
},
});
return false;
}
function show_vocabulary_info()
{
vocabulary_name = $('#vocabulary-select').val();
if(vocabulary_name)
{
$('#vocabulary-perm-management').load(ajax_vocab_perm_manage_form, "vocabulary_name="+vocabulary_name);
$('#vocabulary-statistisc').load(ajax_get_vocabulary_stats, "vocabulary_name="+vocabulary_name);
}
else
{
$('#vocabulary-perm-management').empty();
$('#vocabulary-statistisc').load(ajax_get_vocabulary_stats, "vocabulary_name=");
}
}
function download_form_submit() {
ShowProgressAnimation();
this_form = $(this);
form_data = this_form.serializeArray();
var vocabularies = new Array();
var frame_opinions = new Array();
var lemma_statuses = new Array();
var owners = new Array();
var poss = new Array();
var addframeopinion = false;
form_data = $.map(form_data, function(elem)
{
if (elem.name != 'vocabulary' && elem.name != 'format' &&
elem.name != 'frame_opinion' && elem.name != 'lemma_status' &&
elem.name != 'owner' && elem.name != 'addframeopinion' &&
elem.name != 'pos')
return elem;
else {
if (elem.name == 'vocabulary')
vocabularies.push(elem.value);
else if (elem.name == 'pos')
poss.push(elem.value);
else if (elem.name == 'format')
format = elem.value;
else if (elem.name == 'frame_opinion')
frame_opinions.push(elem.value);
else if (elem.name == 'lemma_status')
lemma_statuses.push(elem.value);
else if (elem.name == 'owner')
owners.push(elem.value);
else if (elem.name == 'addframeopinion')
addframeopinion = elem.value;
}
});
form_data.push({name: 'vocabularies', value: vocabularies});
form_data.push({name: 'poss', value: poss});
form_data.push({name: 'format', value: format});
form_data.push({name: 'frame_opinions', value: frame_opinions});
form_data.push({name: 'lemma_statuses', value: lemma_statuses});
form_data.push({name: 'owners', value: owners});
form_data.push({name: 'addframeopinion', value: addframeopinion});
$.ajaxJSON({
method: 'post',
url: ajax_create_vocabulary,
data: {
form_data: form_data
},
callback: function(result) {
HideProgressAnimation();
lemma_view_location = window.location.toString();
// trzeba by to moze z czasem poprawic na cos madrzejszego
var url = lemma_view_location.replace('/slowniki/', '/slowniki/'+result['file_name']);
window.open(url,'Download');
},
error_callback: function(xhr, status, error) {
HideProgressAnimation();
error_alert(status + ': ' + error);
},
bad_data_callback: function(result) {
if (result == 'format not selected') {
HideProgressAnimation();
error_alert('Wybierz format pliku wyjściowego.');
return false;
}
else if (result == 'creating vocabulary error') {
HideProgressAnimation();
error_alert('Nie udało się utworzyć słownika.');
return false;
}
else
{
HideProgressAnimation();
return true;
}
},
});
return false;
}
function get_vocabulary_file(vocabulary_name, format) {
ShowProgressAnimation();
if(!vocabulary_name || !format)
{
HideProgressAnimation();
error_alert('Wybierz słownik i format pliku wyjściowego.');
return false;
}
$.ajaxJSON({
method: 'post',
url: ajax_create_vocabulary,
data: {
vocabulary_name: vocabulary_name,
format: format
},
callback: function(result) {
HideProgressAnimation();
lemma_view_location = window.location.toString();
// trzeba by to moze z czasem poprawic na cos madrzejszego
var url = lemma_view_location.replace('/slowniki/', '/slowniki/'+vocabulary_name);
window.open(url,'Download');
},
error_callback: function(xhr, status, error) {
HideProgressAnimation();
},
bad_data_callback: function(result) {
if (result == 'creating vocabulary error') {
HideProgressAnimation();
error_alert('Wystąpił błąd podczas tworzenia pliku słownikowego.');
return false;
}
else
{
HideProgressAnimation();
return true;
}
},
});
return false;
}