-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcatalog_admin.js
240 lines (211 loc) · 5.41 KB
/
catalog_admin.js
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
function attach_survey_handler(){
$("#surveys .icon, #surveys .chk").click(function(event){
event.stopImmediatePropagation();
});
$("#surveys .row").click(function (e) {
var $row=$(this);
rowid=$(this).attr("id");
surveyid=rowid.substr(2);
row_info_id="#"+rowid+'_info';
row_sel_id="#"+rowid;
//already selected, reset
if ($row.data('active')==1) {
$row.removeClass().addClass("row");
$(row_info_id).removeClass("show").addClass("hide");
$row.data('active',0);
return false;
}
else{
//collapse any expanded rows
$("#surveys .selected").removeClass().addClass("row");
$("#surveys .show").removeClass("show").addClass("hide");
}
//add custom data to active row
$(row_sel_id).data('active', 1);
$(row_sel_id).toggleClass("selected");
$(row_info_id).removeClass("hide").addClass("show");
$(row_info_id+" > td").html('<div class="info"><img src="images/loading.gif" alt=""/>'+i18n.js_loading+'</div>');
$.ajax({
type: "GET",
url: site_url+"/admin/catalog/survey/"+surveyid,
cache: false,
timeout:20000,
success: function(data) {
$(row_info_id+" > td").html(data);
},
error: function(XMLHttpRequest, textStatus, errorThrow) {
alert("error");
$('#surveys').html('<div class="error">Search failed<br>'+XMLHttpRequest.responseText+'</div>');
}
});
return false;
});
}
function popup_dialog(obj) {
var settings = {
centerBrowser:1,
centerScreen:1,
height:600,
left:0,
location:0,
menubar:0,
resizable:1,
scrollbars:1,
status:0,
width:800,
windowName:$(obj).attr("id"),
windowURL:$(obj).attr("href"),
top:0,
toolbar:0
};
var windowFeatures = 'height=' + settings.height +
',width=' + settings.width +
',toolbar=' + settings.toolbar +
',scrollbars=' + settings.scrollbars +
',status=' + settings.status +
',resizable=' + settings.resizable +
',location=' + settings.location +
',menuBar=' + settings.menubar;
if ($.browser.msie) {//IE hack
centeredY = (window.screenTop - 120) + ((((document.documentElement.clientHeight + 120)/2) - (settings.height/2)));
centeredX = window.screenLeft + ((((document.body.offsetWidth + 20)/2) - (settings.width/2)));
}else{
centeredY = window.screenY + (((window.outerHeight/2) - (settings.height/2)));
centeredX = window.screenX + (((window.outerWidth/2) - (settings.width/2)));
}
window.open(settings.windowURL, settings.windowName, windowFeatures+",left="+centeredX+",top="+centeredY).focus();
return false;
}
jQuery(document).ready(function(){
//checkbox select/deselect
$("#chk_toggle").live("click",function(e){
$('.chk').each(function(){
this.checked = (e.target).checked;
});
});
$(".chk").live("click",function(e){
if (this.checked==false){
$("#chk_toggle").attr('checked', false);
}
});
$("#batch_actions_apply").click(
function (e){
if( $("#batch_actions").val()=="delete"){
batch_delete();
}
else if ($("#batch_actions").val()=="transfer"){
batch_transfer_ownership();
}
else if ($("#batch_actions").val()=="publish"){
batch_publish(1);
}
else if ($("#batch_actions").val()=="unpublish"){
batch_publish(0);
}
}
);
//attach_hover();
attach_survey_handler();
//page change
$('#ps').change(function() {
$('#catalog-search').submit();
});
});
function batch_delete(){
if ($('.chk:checked').length==0){
alert(i18n.no_item_selected);
return false;
}
if (!confirm(i18n.confirm_delete))
{
return false;
}
selected='';
$('.chk:checked').each(function(){
if (selected!=''){selected+=',';}
selected+= this.value;
});
$.ajax({
timeout:1000*120,
cache:false,
dataType: "json",
data:{ submit: "submit"},
type:'POST',
url: CI.base_url+'/admin/catalog/delete/'+selected+'/?ajax=true',
success: function(data) {
if (data.success){
location.reload();
}
else{
alert(data.error);
}
},
error: function(XHR, textStatus, thrownError) {
alert("Error occured " + XHR.status);
}
});
}
function batch_transfer_ownership()
{
if ($('.chk:checked').length==0){
alert(i18n.no_item_selected);
return false;
}
selected='';
$('.chk:checked').each(function(){
if (selected!=''){selected+=',';}
selected+= this.value;
});
window.location= CI.base_url+'/admin/catalog/transfer/'+selected;
}
function batch_publish(publish)
{
if ($('.chk:checked').length==0){
alert(i18n.no_item_selected);
return false;
}
selected='';
$('.chk:checked').each(function(){
if (selected!=''){selected+=',';}
selected+= this.value;
});
window.location= CI.base_url+'/admin/catalog/publish/'+selected+'/'+publish;
}
function share_ddi(e,surveyid)
{
share=0;
if ($("#"+e.id).is(':checked')==true) {share=1;}
url=CI.base_url+'/admin/catalog/shareddi/'+surveyid+'/'+share;
$.get(url);
}
function attach_note(sid,type)
{
var note_text="";
if (type=="reviewer")
{
note_text=$("#reviewer_note_"+sid).val();
}
else
{
note_text=$("#admin_note_"+sid).val();
}
$.ajax({
timeout:1000*120,
cache:false,
dataType: "json",
data:{ note: note_text},
type:'POST',
url: CI.base_url+'/admin/catalog/attach_note/'+sid+'/'+type,
success: function(data) {
if (data.success){
alert(data.success);
}
else{
alert(data.error);
}
},
error: function(XHR, textStatus, thrownError) {
alert("Error occured " + XHR.status);
}
});
}