| 1 |
jQuery(function($){ |
| 2 |
|
| 3 |
$('#wpcomments-tabs').tabs(); |
| 4 |
|
| 5 |
|
| 6 |
var meta_removed; |
| 7 |
|
| 8 |
//attaching hide and delete events for existing meta data |
| 9 |
$("#file-meta-input-holder li").each(function(i, item){ |
| 10 |
$(item).find(".ui-icon-carat-2-n-s").click(function(e) { |
| 11 |
$(item).find("table").slideToggle(300); |
| 12 |
}); |
| 13 |
// for delete box |
| 14 |
$(item).find(".ui-icon-trash").click(function(e) { |
| 15 |
$("#remove-meta-confirm").dialog("open"); |
| 16 |
meta_removed = $(item); |
| 17 |
}); |
| 18 |
}); |
| 19 |
|
| 20 |
$('.ui-icon-circle-triangle-n').click(function(e){ |
| 21 |
$("#file-meta-input-holder li").find('table').slideUp(); |
| 22 |
}); |
| 23 |
$('.ui-icon-circle-triangle-s').click(function(e){ |
| 24 |
$("#file-meta-input-holder li").find('table').slideDown(); |
| 25 |
}); |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
$("#file-meta-input-holder").sortable({ |
| 30 |
revert : true, |
| 31 |
stop : function(event, ui) { |
| 32 |
// console.log(ui); |
| 33 |
|
| 34 |
// only attach click event when dropped from right panel |
| 35 |
if (ui.originalPosition.left > 20) { |
| 36 |
$(ui.item).find(".ui-icon-carat-2-n-s").click(function(e) { |
| 37 |
$(this).parent('.postbox').find("table").slideToggle(300); |
| 38 |
}); |
| 39 |
|
| 40 |
// for delete box |
| 41 |
$(ui.item).find(".ui-icon-trash").click(function(e) { |
| 42 |
$("#remove-meta-confirm").dialog("open"); |
| 43 |
meta_removed = $(ui.item); |
| 44 |
}); |
| 45 |
} |
| 46 |
} |
| 47 |
}); |
| 48 |
|
| 49 |
// =========== remove dialog =========== |
| 50 |
$("#remove-meta-confirm").dialog({ |
| 51 |
resizable : false, |
| 52 |
height : 160, |
| 53 |
autoOpen : false, |
| 54 |
modal : true, |
| 55 |
buttons : { |
| 56 |
"Remove" : function() { |
| 57 |
$(this).dialog("close"); |
| 58 |
meta_removed.remove(); |
| 59 |
}, |
| 60 |
Cancel : function() { |
| 61 |
$(this).dialog("close"); |
| 62 |
} |
| 63 |
} |
| 64 |
}); |
| 65 |
|
| 66 |
$("#nm-input-types li").draggable( |
| 67 |
{ |
| 68 |
connectToSortable : "#file-meta-input-holder", |
| 69 |
helper : "clone", |
| 70 |
revert : "invalid", |
| 71 |
start: function(event, ui){ |
| 72 |
$("#form-meta-setting ul li").find('table').slideUp(); |
| 73 |
ui.helper.height('auto'); |
| 74 |
}, |
| 75 |
stop : function(event, ui) { |
| 76 |
ui.helper.width('100%'); |
| 77 |
ui.helper.height('auto'); |
| 78 |
|
| 79 |
$('.ui-sortable .ui-draggable').removeClass( |
| 80 |
'input-type-item').find('div').addClass('postbox'); |
| 81 |
|
| 82 |
// now replacing the icons with arrow |
| 83 |
$('.postbox').find('.ui-icon-arrow-4').removeClass( |
| 84 |
'ui-icon-arrow-4').addClass('ui-icon-carat-2-n-s'); |
| 85 |
$('.postbox').find('.ui-icon-placehorder').removeClass( |
| 86 |
'ui-icon-placehorder').addClass( |
| 87 |
'ui-icon ui-icon-trash'); |
| 88 |
|
| 89 |
} |
| 90 |
}); |
| 91 |
|
| 92 |
// ================== new meta form creator =================== |
| 93 |
}); |
| 94 |
|
| 95 |
function update_options(options){ |
| 96 |
|
| 97 |
var opt = jQuery.parseJSON(options); |
| 98 |
|
| 99 |
jQuery("#wpcomment-settigns-saving").html('<img src="'+wpcomments_vars.doing+'" />'); |
| 100 |
/* |
| 101 |
* getting action from object |
| 102 |
*/ |
| 103 |
|
| 104 |
|
| 105 |
/* |
| 106 |
* extractElementData |
| 107 |
* defined in nm-globals.js |
| 108 |
*/ |
| 109 |
var data = extractElementData(opt); |
| 110 |
|
| 111 |
|
| 112 |
if (data.bug) { |
| 113 |
//jQuery("#reply_err").html('Red are required'); |
| 114 |
alert('bug here'); |
| 115 |
} else { |
| 116 |
|
| 117 |
/* |
| 118 |
* [1] |
| 119 |
* TODO: change action name below with prefix plugin shortname_action_name |
| 120 |
*/ |
| 121 |
data.action = 'wpcomments_save_settings'; |
| 122 |
|
| 123 |
jQuery.post(ajaxurl, data, function(resp) { |
| 124 |
|
| 125 |
jQuery("#wpcomment-settigns-saving").html(resp); |
| 126 |
// alert(resp); |
| 127 |
window.location.reload(true); |
| 128 |
|
| 129 |
}); |
| 130 |
} |
| 131 |
|
| 132 |
/*jQuery.each(res, function(i, item){ |
| 133 |
|
| 134 |
alert(i); |
| 135 |
|
| 136 |
});*/ |
| 137 |
} |
| 138 |
|
| 139 |
/* ================ below script is for admin settings framework ============== */ |
| 140 |
|
| 141 |
// saving form meta |
| 142 |
function save_file_meta() { |
| 143 |
|
| 144 |
|
| 145 |
jQuery("#nm-saving-form").html('<img src="'+wpcomments_vars.doing+'" />'); |
| 146 |
|
| 147 |
var form_meta_values = new Array(); // {}; //Array(); |
| 148 |
jQuery("#file-meta-input-holder li") |
| 149 |
.each( |
| 150 |
function(i, item) { |
| 151 |
|
| 152 |
var inner_array = {}; |
| 153 |
inner_array['type'] = jQuery(item).attr( |
| 154 |
'data-inputtype'); |
| 155 |
|
| 156 |
jQuery(this) |
| 157 |
.find('td.table-column-input') |
| 158 |
.each( |
| 159 |
function(i, col) { |
| 160 |
|
| 161 |
var meta_input_type = jQuery(col) |
| 162 |
.attr('data-type'); |
| 163 |
var meta_input_name = jQuery(col) |
| 164 |
.attr('data-name'); |
| 165 |
var cb_value = ''; |
| 166 |
if (meta_input_type == 'checkbox') { |
| 167 |
cb_value = (jQuery(this).find('input:checkbox[name="' + meta_input_name + '"]:checked').val() === undefined ? '' : jQuery(this).find('input:checkbox[name="' + meta_input_name + '"]:checked').val()); |
| 168 |
inner_array[meta_input_name] = cb_value; |
| 169 |
} else if (meta_input_type == 'textarea') { |
| 170 |
inner_array[meta_input_name] = jQuery( |
| 171 |
this) |
| 172 |
.find( |
| 173 |
'textarea[name="' |
| 174 |
+ meta_input_name |
| 175 |
+ '"]') |
| 176 |
.val(); |
| 177 |
} else if (meta_input_type == 'select') { |
| 178 |
inner_array[meta_input_name] = jQuery( |
| 179 |
this) |
| 180 |
.find( |
| 181 |
'select[name="' |
| 182 |
+ meta_input_name |
| 183 |
+ '"]') |
| 184 |
.val(); |
| 185 |
} else if (meta_input_type == 'html-conditions') { |
| 186 |
|
| 187 |
var all_conditions = {}; |
| 188 |
var the_conditions = new Array(); //{}; |
| 189 |
|
| 190 |
all_conditions['visibility'] = jQuery( |
| 191 |
this) |
| 192 |
.find( |
| 193 |
'select[name="condition_visibility"]') |
| 194 |
.val(); |
| 195 |
all_conditions['bound'] = jQuery( |
| 196 |
this) |
| 197 |
.find( |
| 198 |
'select[name="condition_bound"]') |
| 199 |
.val(); |
| 200 |
jQuery(this).find('div').each(function(i, div_box){ |
| 201 |
|
| 202 |
var the_rule = {}; |
| 203 |
|
| 204 |
the_rule['elements'] = jQuery( |
| 205 |
this) |
| 206 |
.find( |
| 207 |
'select[name="condition_elements"]') |
| 208 |
.val(); |
| 209 |
the_rule['operators'] = jQuery( |
| 210 |
this) |
| 211 |
.find( |
| 212 |
'select[name="condition_operators"]') |
| 213 |
.val(); |
| 214 |
the_rule['element_values'] = jQuery( |
| 215 |
this) |
| 216 |
.find( |
| 217 |
'select[name="condition_element_values"]') |
| 218 |
.val(); |
| 219 |
|
| 220 |
the_conditions.push(the_rule); |
| 221 |
}); |
| 222 |
|
| 223 |
all_conditions['rules'] = the_conditions; |
| 224 |
inner_array[meta_input_name] = all_conditions; |
| 225 |
}else if (meta_input_type == 'pre-images') { |
| 226 |
var all_preuploads = new Array(); |
| 227 |
jQuery(this).find('div.pre-upload-box table').each(function(i, preupload_box){ |
| 228 |
var pre_upload_obj = { link: jQuery(preupload_box).find('input[name="pre-upload-link"]').val(), |
| 229 |
title: jQuery(preupload_box).find('input[name="pre-upload-title"]').val(), |
| 230 |
price: jQuery(preupload_box).find('input[name="pre-upload-price"]').val(),}; |
| 231 |
|
| 232 |
all_preuploads.push(pre_upload_obj); |
| 233 |
}); |
| 234 |
|
| 235 |
inner_array['images'] = all_preuploads; |
| 236 |
|
| 237 |
} else { |
| 238 |
inner_array[meta_input_name] = jQuery.trim(jQuery(this).find('input[name="'+ meta_input_name+ '"]').val()) |
| 239 |
// inner_array.push(temp); |
| 240 |
} |
| 241 |
|
| 242 |
}); |
| 243 |
|
| 244 |
form_meta_values.push(inner_array); |
| 245 |
|
| 246 |
}); |
| 247 |
|
| 248 |
//console.log(form_meta_values); return false; |
| 249 |
// ok data is collected, so send it to server now Huh? |
| 250 |
|
| 251 |
|
| 252 |
do_action = 'wpcomments_save_file_meta'; |
| 253 |
|
| 254 |
var server_data = { |
| 255 |
action : do_action, |
| 256 |
file_meta : form_meta_values |
| 257 |
} |
| 258 |
|
| 259 |
jQuery.post(ajaxurl, server_data, function(resp) { |
| 260 |
|
| 261 |
console.log(resp); |
| 262 |
if (resp.status == 'success') { |
| 263 |
|
| 264 |
jQuery("#nm-saving-form").html(resp.message); |
| 265 |
window.location.reload(true); |
| 266 |
} |
| 267 |
|
| 268 |
}, 'json'); |
| 269 |
|
| 270 |
} |
| 271 |
|
| 272 |
/* |
| 273 |
* extract data from html elements |
| 274 |
*/ |
| 275 |
|
| 276 |
function extractElementData(elements) { |
| 277 |
|
| 278 |
var data = new Object; |
| 279 |
|
| 280 |
data.bug = false; |
| 281 |
jQuery.each(elements, |
| 282 |
function(i, item) { |
| 283 |
|
| 284 |
if(item.req == undefined || item.req == 0){ |
| 285 |
item.req = false; |
| 286 |
|
| 287 |
}else{ |
| 288 |
item.req = true; |
| 289 |
|
| 290 |
} |
| 291 |
|
| 292 |
switch (item.type) { |
| 293 |
|
| 294 |
case 'text': |
| 295 |
|
| 296 |
data[i] = jQuery("input[name^='" + i + "']").val(); |
| 297 |
if(jQuery("input[name^='" + i + "']").val() == '' && item.req){ |
| 298 |
jQuery("input[name^='" + i + "']").css('border', 'red 1px solid'); |
| 299 |
data.bug = true; |
| 300 |
/*alert(item.type+' is required');*/ |
| 301 |
} |
| 302 |
break; |
| 303 |
|
| 304 |
case 'select': |
| 305 |
|
| 306 |
data[i] = jQuery("select[name^='" + i + "']").val(); |
| 307 |
if(jQuery("select[name^='" + i + "']").val() == '' && item.req){ |
| 308 |
jQuery("select[name^='" + i + "']").css('border', 'red 1px solid'); |
| 309 |
data.bug = true; |
| 310 |
/*alert(item.type+' is required');*/ |
| 311 |
} |
| 312 |
break; |
| 313 |
|
| 314 |
case 'checkbox': |
| 315 |
|
| 316 |
var checkedVals = []; |
| 317 |
jQuery('input:checkbox[name^="' + i + '"]:checked').each(function() { |
| 318 |
checkedVals.push(jQuery(this).val()); |
| 319 |
}); |
| 320 |
|
| 321 |
data[i] = (checkedVals.length == 0) ? null : checkedVals; |
| 322 |
|
| 323 |
if (!jQuery("input:checkbox[name^='" + i + "']").is(':checked') && item.req){ |
| 324 |
|
| 325 |
jQuery("input:checkbox[name^='" + i + "']").parent('label').css('color', 'red'); |
| 326 |
data.bug = true; |
| 327 |
/*alert(item.type+' is required');*/ |
| 328 |
} |
| 329 |
|
| 330 |
break; |
| 331 |
|
| 332 |
case 'radio': |
| 333 |
|
| 334 |
data[i] = jQuery( |
| 335 |
"input:radio[name^='" + i + "']:checked").val(); |
| 336 |
if (!jQuery("input:radio[name^='" + i + "']").is(':checked') && item.req){ |
| 337 |
|
| 338 |
jQuery("input:radio[name^='" + i + "']").css('border', 'red 1px solid'); |
| 339 |
data.bug = true; |
| 340 |
alert(item.type+' is required'); |
| 341 |
} |
| 342 |
break; |
| 343 |
|
| 344 |
case 'textarea': |
| 345 |
|
| 346 |
data[i] = jQuery("textarea[name^='" + i + "']").val(); |
| 347 |
|
| 348 |
if(jQuery("textarea[name^='" + i + "']").val() == '' && item.req){ |
| 349 |
jQuery("textarea[name^='" + i + "']").css('border', 'red 1px solid'); |
| 350 |
data.bug = true; |
| 351 |
/*alert(item.type+' is required');*/ |
| 352 |
} |
| 353 |
break; |
| 354 |
} |
| 355 |
|
| 356 |
}); |
| 357 |
|
| 358 |
return data; |
| 359 |
} |
| 360 |
|
| 361 |
|
| 362 |
/* |
| 363 |
* function checking the checkbox for current value |
| 364 |
* current value: json object |
| 365 |
* @Author: Najeeb |
| 366 |
* 13 Oct, 2012 |
| 367 |
*/ |
| 368 |
|
| 369 |
function setChecked(elementName, currentValue){ |
| 370 |
|
| 371 |
var elementCB = jQuery('input:checkbox[name="' + elementName + '"]'); |
| 372 |
|
| 373 |
var currentValues = jQuery.parseJSON(currentValue); |
| 374 |
|
| 375 |
|
| 376 |
//console.log(currentValues); |
| 377 |
|
| 378 |
jQuery.each(elementCB, function(i, item){ |
| 379 |
|
| 380 |
//console.log(item.id); |
| 381 |
var current_cb_id = item.id; |
| 382 |
|
| 383 |
jQuery.each(currentValues, function(i, item){ |
| 384 |
|
| 385 |
//console.log(item + jQuery("#"+current_cb_id).attr('value')); |
| 386 |
if(jQuery("#"+current_cb_id).attr('value') == item){ |
| 387 |
|
| 388 |
jQuery("#"+current_cb_id).attr('checked', true); |
| 389 |
}else{ |
| 390 |
if ( jQuery("#"+current_cb_id).attr('checked') == true) |
| 391 |
jQuery("#"+current_cb_id).attr('checked', false); |
| 392 |
} |
| 393 |
//jQuery('input:checkbox[value="' + item + '"]').attr("checked", "checked"); |
| 394 |
}); |
| 395 |
}); |
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
} |
| 400 |
|
| 401 |
/* |
| 402 |
* function checking the RADIO for current value |
| 403 |
* current value: single |
| 404 |
* @Author: Najeeb |
| 405 |
* 3 July, 2012 |
| 406 |
*/ |
| 407 |
|
| 408 |
function setCheckedRadio(elementName, currentValue) { |
| 409 |
|
| 410 |
var elementRadio = jQuery('input:radio[name="' + elementName + '"]'); |
| 411 |
|
| 412 |
//console.log(elementRadio); |
| 413 |
jQuery.each(elementRadio, function(i, item) { |
| 414 |
|
| 415 |
//console.log(item.id); |
| 416 |
var current_radio_id = item.id; |
| 417 |
|
| 418 |
if (jQuery("#" + current_radio_id).attr('value') == currentValue) { |
| 419 |
|
| 420 |
jQuery("#" + current_radio_id).attr('checked', true); |
| 421 |
} else { |
| 422 |
if (jQuery("#" + current_radio_id).attr('checked') == true) |
| 423 |
jQuery("#" + current_radio_id).attr('checked', false); |
| 424 |
} |
| 425 |
|
| 426 |
}); |
| 427 |
|
| 428 |
} |
| 429 |
|