custom.js
841 lines
| 1 | var defaultFolderHtml; |
| 2 | var folderID = 0; |
| 3 | var fileAddUpdateStatus = "add"; |
| 4 | var fileFolderID = 0; |
| 5 | var folderNameDynamic = ''; |
| 6 | var totalFolders = -1; |
| 7 | var isKeyActive = 0; |
| 8 | var folderLimitation = 10; |
| 9 | |
| 10 | var listFolderString = "<li class='grid-view' data-id='__folder_id__' id='folder___folder_id__'>" + |
| 11 | "<div class='folder-item is-folder' data-id='__folder_id__'>" + |
| 12 | "<a title='__folder_name__' id='folder_view___folder_id__'" + |
| 13 | "class='folder-view __append_class__'" + |
| 14 | "data-id='__folder_id__'>" + |
| 15 | "<span class='folder item-name'><span id='wcp_folder_text___folder_id__'" + |
| 16 | "class='folder-title'>__folder_name__</span></span>" + |
| 17 | "</a>" + |
| 18 | "</div>" + |
| 19 | "</li>"; |
| 20 | |
| 21 | function addFolder() { |
| 22 | if(isKeyActive == 0 && totalFolders >= folderLimitation) { |
| 23 | Swal.fire({ |
| 24 | title: "You've reached the "+totalFolders+" folder limitation!", |
| 25 | text: "Unlock unlimited amount of folders by upgrading to one of our pro plans.", |
| 26 | type: 'warning', |
| 27 | showCancelButton: true, |
| 28 | confirmButtonColor: '#3085d6', |
| 29 | cancelButtonColor: '#d33', |
| 30 | confirmButtonText: 'See Pro Plans' |
| 31 | }).then((result) => { |
| 32 | if (result.value) { |
| 33 | window.location = wcp_settings.register_url; |
| 34 | } |
| 35 | }); |
| 36 | return false; |
| 37 | } |
| 38 | folderOrder = jQuery("#space_"+fileFolderID+" > li").length+1; |
| 39 | ajaxURL = wcp_settings.ajax_url+"?parent_id=" + fileFolderID + "&type=" + wcp_settings.post_type + "&action=wcp_add_new_folder&term_id=" + fileFolderID + "&order=" + folderOrder+"&name="; |
| 40 | Swal({ |
| 41 | title: 'Add Folder', |
| 42 | input: 'text', |
| 43 | inputAttributes: { |
| 44 | autocapitalize: 'off', |
| 45 | placeholder: "Folder name" |
| 46 | }, |
| 47 | showCancelButton: true, |
| 48 | confirmButtonText: 'Submit', |
| 49 | showLoaderOnConfirm: true, |
| 50 | reverseButtons: true, |
| 51 | preConfirm: (folderName) => { |
| 52 | if(folderName == "") { |
| 53 | swal.showValidationError( |
| 54 | 'Please enter folder name' |
| 55 | ) |
| 56 | return false; |
| 57 | } |
| 58 | return fetch(ajaxURL+folderName) |
| 59 | .then(response => { |
| 60 | if (!response.ok) { |
| 61 | throw new Error(response.statusText); |
| 62 | } |
| 63 | return response.json(); |
| 64 | }).catch(error => { |
| 65 | Swal.showValidationMessage( |
| 66 | "Request failed: "+error |
| 67 | ) |
| 68 | }); |
| 69 | }, |
| 70 | allowOutsideClick: () => !Swal.isLoading() |
| 71 | }).then((result) => { |
| 72 | if(result.value.error == 1) { |
| 73 | Swal({ |
| 74 | type: 'error', |
| 75 | title: 'Oops...', |
| 76 | text: result.value.message |
| 77 | }); |
| 78 | } else if(result.value.status == 1) { |
| 79 | jQuery("#space_"+result.value.parent_id).append(result.value.term_data); |
| 80 | jQuery("#wcp_folder_"+result.value.parent_id).addClass("active has-sub-tree"); |
| 81 | isKeyActive = parseInt(result.value.is_key_active); |
| 82 | totalFolders = parseInt(result.value.folders); |
| 83 | jQuery("#current-folder").text(totalFolders); |
| 84 | if(totalFolders > folderLimitation) { |
| 85 | folderLimitation = totalFolders; |
| 86 | } |
| 87 | jQuery("#total-folder").text(folderLimitation); |
| 88 | checkForExpandCollapse(); |
| 89 | add_menu_to_list(); |
| 90 | } |
| 91 | }); |
| 92 | } |
| 93 | |
| 94 | |
| 95 | function updateFolder() { |
| 96 | folderName = jQuery.trim(jQuery("#wcp_folder_"+fileFolderID+" > h3").text()); |
| 97 | parentID = jQuery("#wcp_folder_"+fileFolderID).closest("li.route").data("folder-id"); |
| 98 | if(parentID == undefined) { |
| 99 | parentID = 0; |
| 100 | } |
| 101 | ajaxURL = wcp_settings.ajax_url+"?parent_id=" + parentID + "&type=" + wcp_settings.post_type + "&action=wcp_update_folder&term_id=" + fileFolderID + "&name="; |
| 102 | Swal({ |
| 103 | title: 'Update Folder', |
| 104 | input: 'text', |
| 105 | inputValue: folderName, |
| 106 | inputAttributes: { |
| 107 | autocapitalize: 'off', |
| 108 | placeholder: "Folder name", |
| 109 | value: folderName |
| 110 | }, |
| 111 | showCancelButton: true, |
| 112 | confirmButtonText: 'Submit', |
| 113 | showLoaderOnConfirm: true, |
| 114 | reverseButtons: true, |
| 115 | preConfirm: (folderName) => { |
| 116 | if(folderName == "") { |
| 117 | swal.showValidationError( |
| 118 | 'Please enter folder name' |
| 119 | ) |
| 120 | return false; |
| 121 | } |
| 122 | return fetch(ajaxURL+folderName) |
| 123 | .then(response => { |
| 124 | if (!response.ok) { |
| 125 | throw new Error(response.statusText); |
| 126 | } |
| 127 | return response.json(); |
| 128 | }).catch(error => { |
| 129 | Swal.showValidationMessage( |
| 130 | "Request failed: "+error |
| 131 | ) |
| 132 | }); |
| 133 | }, |
| 134 | allowOutsideClick: () => !Swal.isLoading() |
| 135 | }).then((result) => { |
| 136 | if(result.value.error == 1) { |
| 137 | Swal({ |
| 138 | type: 'error', |
| 139 | title: 'Oops...', |
| 140 | text: result.value.message |
| 141 | }); |
| 142 | } else if(result.value.status == 1) { |
| 143 | jQuery("#wcp_folder_"+result.value.id+" > h3 > .title-text").text(result.value.term_title); |
| 144 | jQuery("#wcp_folder_"+result.value.id+" > h3").attr("title",result.value.term_title); |
| 145 | add_menu_to_list(); |
| 146 | } |
| 147 | }); |
| 148 | } |
| 149 | |
| 150 | function add_menu_to_list() { |
| 151 | folderId = 0; |
| 152 | if(jQuery(".active-term").length) { |
| 153 | folderId = jQuery(".active-term").data("folder-id"); |
| 154 | } |
| 155 | jQuery(".tree-structure ul").html(""); |
| 156 | jQuery("#space_"+folderId).children().each(function(){ |
| 157 | fID = jQuery(this).data("folder-id"); |
| 158 | fName = jQuery(this).find("h3.title:first .title-text").text() |
| 159 | liHtml = listFolderString.replace(/__folder_id__/g,fID); |
| 160 | liHtml = liHtml.replace(/__folder_name__/g,fName); |
| 161 | selectedClass = jQuery(this).hasClass("is-high")?"is-high":""; |
| 162 | liHtml = liHtml.replace(/__append_class__/g,selectedClass); |
| 163 | jQuery(".tree-structure ul").append(liHtml); |
| 164 | }); |
| 165 | } |
| 166 | |
| 167 | jQuery(document).ready(function(){ |
| 168 | |
| 169 | isKeyActive = parseInt(wcp_settings.is_key_active); |
| 170 | totalFolders = parseInt(wcp_settings.folders); |
| 171 | |
| 172 | if(wcp_settings.post_type == "attachment") { |
| 173 | jQuery(".wp-header-end").before('<div class="tree-structure"><ul></ul><div class="clear clearfix"></div></div>'); |
| 174 | |
| 175 | add_menu_to_list(); |
| 176 | } |
| 177 | |
| 178 | calcWidth(jQuery('#title_0')); |
| 179 | window.onresize = function(event) { |
| 180 | console.log("window resized"); |
| 181 | |
| 182 | }; |
| 183 | |
| 184 | jQuery("#cancel-button").click(function(){ |
| 185 | jQuery(".wcp-form-data").hide(); |
| 186 | }); |
| 187 | |
| 188 | |
| 189 | jQuery(document).on("click", "h3.title", function(e) { |
| 190 | e.stopPropagation(); |
| 191 | window.location = wcp_settings.page_url+jQuery(this).closest("li.route").data("slug"); |
| 192 | }); |
| 193 | |
| 194 | jQuery(".tree-structure a").livequery(function(){ |
| 195 | jQuery(this).click(function(){ |
| 196 | fID = jQuery(this).data("id"); |
| 197 | jQuery("#title_"+fID).trigger("click"); |
| 198 | }); |
| 199 | }); |
| 200 | |
| 201 | jQuery(".wcp-parent > span").click(function(){ |
| 202 | window.location = wcp_settings.page_url |
| 203 | }); |
| 204 | |
| 205 | jQuery("h3.title").livequery(function(){ |
| 206 | jQuery(this).droppable({ |
| 207 | accept: ".wcp-move-file, .wcp-move-multiple, .attachments-browser li.attachment", |
| 208 | hoverClass: 'wcp-drop-hover', |
| 209 | classes: { |
| 210 | "ui-droppable-active": "ui-state-highlight" |
| 211 | }, |
| 212 | drop: function( event, ui ) { |
| 213 | folderID = jQuery(this).closest("li.route").data('folder-id'); |
| 214 | if ( ui.draggable.hasClass( 'wcp-move-multiple' ) ) { |
| 215 | if(jQuery(".wp-list-table input:checked").length) { |
| 216 | chkStr = ""; |
| 217 | jQuery(".wp-list-table input:checked").each(function(){ |
| 218 | chkStr += jQuery(this).val()+","; |
| 219 | }); |
| 220 | jQuery.ajax({ |
| 221 | url: wcp_settings.ajax_url, |
| 222 | data: "post_ids=" + chkStr + "&type=" + wcp_settings.post_type + "&action=wcp_change_multiple_post_folder&folder_id=" + folderID, |
| 223 | method: 'post', |
| 224 | success: function (res) { |
| 225 | window.location.reload(); |
| 226 | } |
| 227 | }); |
| 228 | } |
| 229 | } else if( ui.draggable.hasClass( 'wcp-move-file' ) ){ |
| 230 | postID = ui.draggable[0].attributes['data-id'].nodeValue; |
| 231 | jQuery.ajax({ |
| 232 | url: wcp_settings.ajax_url, |
| 233 | data: "post_id=" + postID + "&type=" + wcp_settings.post_type + "&action=wcp_change_post_folder&folder_id=" + folderID, |
| 234 | method: 'post', |
| 235 | success: function (res) { |
| 236 | window.location.reload(); |
| 237 | } |
| 238 | }); |
| 239 | } else if( ui.draggable.hasClass( 'attachment' ) ){ |
| 240 | chkStr = ui.draggable[0].attributes['data-id'].nodeValue; |
| 241 | if(jQuery(".attachments-browser li.attachment.selected").length > 1) { |
| 242 | chkStr = ""; |
| 243 | jQuery(".attachments-browser li.attachment.selected").each(function(){ |
| 244 | chkStr += jQuery(this).data("id")+","; |
| 245 | }); |
| 246 | } |
| 247 | jQuery.ajax({ |
| 248 | url: wcp_settings.ajax_url, |
| 249 | data: "post_ids=" + chkStr + "&type=" + wcp_settings.post_type + "&action=wcp_change_multiple_post_folder&folder_id=" + folderID, |
| 250 | method: 'post', |
| 251 | success: function (res) { |
| 252 | window.location.reload(); |
| 253 | } |
| 254 | }); |
| 255 | } |
| 256 | } |
| 257 | }); |
| 258 | }); |
| 259 | |
| 260 | jQuery(".attachments-browser li.attachment").livequery(function(){ |
| 261 | jQuery(this).draggable({ |
| 262 | revert: "invalid", |
| 263 | containment: "document", |
| 264 | helper: function(event, ui){ |
| 265 | jQuery(".selected-items").remove(); |
| 266 | selectedItems = jQuery(".attachments-browser li.attachment.selected").length; |
| 267 | selectedItems = (selectedItems == 0 || selectedItems == 1)?"1 Item":selectedItems+" Items"; |
| 268 | return jQuery("<div class='selected-items'><span class='total-post-count'>"+selectedItems+" Selected</span></div>"); |
| 269 | }, |
| 270 | start: function( event, ui){ |
| 271 | |
| 272 | }, |
| 273 | cursor: "move", |
| 274 | cursorAt: { |
| 275 | left: 0, |
| 276 | top: 0 |
| 277 | }, |
| 278 | stop: function( event, ui ) { |
| 279 | jQuery(".selected-items").remove(); |
| 280 | } |
| 281 | }); |
| 282 | jQuery(this).draggable("disable"); |
| 283 | }); |
| 284 | |
| 285 | jQuery(".media-button").livequery(function(){ |
| 286 | jQuery(this).click(function() { |
| 287 | |
| 288 | if(jQuery(".delete-selected-button").hasClass("hidden")) { |
| 289 | jQuery(".attachments-browser li.attachment").draggable( "disable" ); |
| 290 | } else { |
| 291 | jQuery(".attachments-browser li.attachment").draggable( "enable" ); |
| 292 | } |
| 293 | |
| 294 | }); |
| 295 | }); |
| 296 | |
| 297 | jQuery(".header-posts").click(function(){ |
| 298 | window.location = wcp_settings.page_url; |
| 299 | }); |
| 300 | |
| 301 | jQuery(".tree-structure .folder-item").livequery(function(){ |
| 302 | jQuery(this).droppable({ |
| 303 | accept: ".wcp-move-file, .wcp-move-multiple, .attachments-browser li.attachment", |
| 304 | hoverClass: 'wcp-drop-hover-list', |
| 305 | classes: { |
| 306 | "ui-droppable-active": "ui-state-highlight" |
| 307 | }, |
| 308 | drop: function( event, ui ) { |
| 309 | console.log(ui); |
| 310 | folderID = jQuery(this).data('id'); |
| 311 | if ( ui.draggable.hasClass( 'wcp-move-multiple' ) ) { |
| 312 | if(jQuery(".wp-list-table input:checked").length) { |
| 313 | chkStr = ""; |
| 314 | jQuery(".wp-list-table input:checked").each(function(){ |
| 315 | chkStr += jQuery(this).val()+","; |
| 316 | }); |
| 317 | jQuery.ajax({ |
| 318 | url: wcp_settings.ajax_url, |
| 319 | data: "post_ids=" + chkStr + "&type=" + wcp_settings.post_type + "&action=wcp_change_multiple_post_folder&folder_id=" + folderID, |
| 320 | method: 'post', |
| 321 | success: function (res) { |
| 322 | window.location.reload(); |
| 323 | } |
| 324 | }); |
| 325 | } |
| 326 | } else if ( ui.draggable.hasClass( 'wcp-move-file' ) ) { |
| 327 | postID = ui.draggable[0].attributes['data-id'].nodeValue; |
| 328 | jQuery.ajax({ |
| 329 | url: wcp_settings.ajax_url, |
| 330 | data: "post_id=" + postID + "&type=" + wcp_settings.post_type + "&action=wcp_change_post_folder&folder_id=" + folderID, |
| 331 | method: 'post', |
| 332 | success: function (res) { |
| 333 | window.location.reload(); |
| 334 | } |
| 335 | }); |
| 336 | } else if( ui.draggable.hasClass( 'attachment' ) ){ |
| 337 | chkStr = ui.draggable[0].attributes['data-id'].nodeValue; |
| 338 | if(jQuery(".attachments-browser li.attachment.selected").length > 1) { |
| 339 | chkStr = ""; |
| 340 | jQuery(".attachments-browser li.attachment.selected").each(function(){ |
| 341 | chkStr += jQuery(this).data("id")+","; |
| 342 | }); |
| 343 | } |
| 344 | jQuery.ajax({ |
| 345 | url: wcp_settings.ajax_url, |
| 346 | data: "post_ids=" + chkStr + "&type=" + wcp_settings.post_type + "&action=wcp_change_multiple_post_folder&folder_id=" + folderID, |
| 347 | method: 'post', |
| 348 | success: function (res) { |
| 349 | window.location.reload(); |
| 350 | } |
| 351 | }); |
| 352 | } |
| 353 | } |
| 354 | }); |
| 355 | }); |
| 356 | |
| 357 | jQuery("#expand-collapse-list").click(function(e){ |
| 358 | e.stopPropagation(); |
| 359 | statusType = 0; |
| 360 | if(jQuery(this).hasClass("all-open")) { |
| 361 | jQuery(this).removeClass("all-open"); |
| 362 | jQuery(".has-sub-tree").removeClass("active"); |
| 363 | statusType = 0; |
| 364 | } else { |
| 365 | jQuery(this).addClass("all-open"); |
| 366 | statusType = 1; |
| 367 | jQuery(".has-sub-tree").addClass("active"); |
| 368 | } |
| 369 | folderIDs = ""; |
| 370 | jQuery(".has-sub-tree").each(function(){ |
| 371 | folderIDs += jQuery(this).data("folder-id")+","; |
| 372 | }); |
| 373 | if(folderIDs != "") { |
| 374 | jQuery(".form-loader-count").css("width","100%"); |
| 375 | jQuery.ajax({ |
| 376 | url: wcp_settings.ajax_url, |
| 377 | data: "type=" + wcp_settings.post_type + "&action=wcp_change_all_status&status=" + statusType + "&folders="+folderIDs, |
| 378 | method: 'post', |
| 379 | success: function (res) { |
| 380 | jQuery(".form-loader-count").css("width","0"); |
| 381 | add_menu_to_list(); |
| 382 | } |
| 383 | }); |
| 384 | } |
| 385 | }); |
| 386 | |
| 387 | resizeDirection = (wcp_settings.isRTL == "1" || wcp_settings.isRTL == 1)?"w":"e"; |
| 388 | jQuery(".wcp-content").resizable( { |
| 389 | resizeHeight: false, |
| 390 | handles: resizeDirection, |
| 391 | minWidth: 305, |
| 392 | maxWidth: 500, |
| 393 | resize: function( e, ui ) { |
| 394 | if(wcp_settings.isRTL == "1") { |
| 395 | jQuery("#wpcontent").css("padding-right", (ui.size.width + 20) + "px"); |
| 396 | jQuery("#wpcontent").css("padding-left", "0px"); |
| 397 | } else { |
| 398 | jQuery("#wpcontent").css("padding-left", (ui.size.width + 20) + "px"); |
| 399 | } |
| 400 | newWidth = ui.size.width - 40; |
| 401 | cssString = ""; |
| 402 | classString = ""; |
| 403 | for(i=0; i<=15; i++) { |
| 404 | classString += " .space > .route >"; |
| 405 | currentWidth = newWidth - (13+(20*i)); |
| 406 | cssString += "#custom-menu > "+classString+" .title { width: "+currentWidth+"px !important; } "; |
| 407 | } |
| 408 | jQuery("#wcp-custom-style").html("<style>"+cssString+"</style>"); |
| 409 | }, |
| 410 | stop: function( e, ui ) { |
| 411 | jQuery.ajax({ |
| 412 | url: wcp_settings.ajax_url, |
| 413 | data: "type=" + wcp_settings.post_type + "&action=wcp_change_post_width&width=" + ui.size.width, |
| 414 | method: 'post', |
| 415 | success: function (res) { |
| 416 | |
| 417 | } |
| 418 | }); |
| 419 | } |
| 420 | }); |
| 421 | |
| 422 | jQuery(".wcp-move-file").draggable({ |
| 423 | /*cancel: "a.ui-icon",*/ |
| 424 | revert: "invalid", |
| 425 | containment: "document", |
| 426 | helper: "clone", |
| 427 | cursor: "move", |
| 428 | start: function( event, ui){ |
| 429 | jQuery(this).closest("td").addClass("wcp-draggable"); |
| 430 | }, |
| 431 | stop: function( event, ui ) { |
| 432 | jQuery(this).closest("td").removeClass("wcp-draggable"); |
| 433 | } |
| 434 | }); |
| 435 | |
| 436 | jQuery(".wcp-move-multiple").draggable({ |
| 437 | /*cancel: "a.ui-icon",*/ |
| 438 | revert: "invalid", |
| 439 | containment: "document", |
| 440 | helper: "clone", |
| 441 | cursor: "move" |
| 442 | }); |
| 443 | |
| 444 | jQuery("h3.title").livequery(function(){ |
| 445 | jQuery(this).on("contextmenu",function(e) { |
| 446 | e.preventDefault(); |
| 447 | isHigh = jQuery(this).closest("li.route").hasClass("is-high"); |
| 448 | jQuery(".dynamic-menu").remove(); |
| 449 | jQuery(".active-menu").removeClass("active-menu"); |
| 450 | menuHtml = "<div class='dynamic-menu'><ul>" + |
| 451 | "<li class='new-folder'><a href='javascript:;'><span class='folder-icon-create_new_folder'></span> New Folder</a></li>" + |
| 452 | "<li class='rename-folder'><a href='javascript:;'><span class='folder-icon-border_color'><span class='path1'></span><span class='path2'></span></span> Rename</a></li>" + |
| 453 | "<li class='mark-folder'><a href='javascript:;'><span class='folder-icon-star_rate'></span>" + ((isHigh) ? " Remove Star" : "Add a Star") + "</a></li>" + |
| 454 | "<li class='remove-folder'><a href='javascript:;'><span class='folder-icon-delete'></span> Delete</a></li>" + |
| 455 | "</ul></div>"; |
| 456 | jQuery(this).after(menuHtml); |
| 457 | jQuery(this).parents("li.route").addClass("active-menu"); |
| 458 | return false; |
| 459 | }); |
| 460 | }); |
| 461 | |
| 462 | jQuery("body").click(function(){ |
| 463 | jQuery(".dynamic-menu").remove(); |
| 464 | jQuery(".active-menu").removeClass("active-menu"); |
| 465 | }); |
| 466 | |
| 467 | jQuery(".dynamic-menu").livequery(function(){ |
| 468 | jQuery(this).click(function(e){ |
| 469 | e.stopPropagation(); |
| 470 | }); |
| 471 | }); |
| 472 | |
| 473 | jQuery(".rename-folder").livequery(function(){ |
| 474 | jQuery(this).click(function(e){ |
| 475 | e.stopPropagation(); |
| 476 | fileFolderID = jQuery(this).closest("li.route").data("folder-id"); |
| 477 | updateFolder(); |
| 478 | add_menu_to_list(); |
| 479 | }); |
| 480 | }); |
| 481 | |
| 482 | jQuery(".mark-folder").livequery(function(){ |
| 483 | jQuery(this).click(function(e){ |
| 484 | e.stopPropagation(); |
| 485 | folderID = jQuery(this).closest("li.route").data("folder-id"); |
| 486 | //console.log("folderID :"+ folderID); |
| 487 | jQuery(".form-loader-count").css("width","100%"); |
| 488 | jQuery(".dynamic-menu").remove(); |
| 489 | jQuery(".active-menu").removeClass("active-menu"); |
| 490 | jQuery.ajax({ |
| 491 | url: wcp_settings.ajax_url, |
| 492 | data: "term_id=" + folderID + "&type=" + wcp_settings.post_type + "&action=wcp_mark_un_mark_folder", |
| 493 | method: 'post', |
| 494 | success: function (res) { |
| 495 | res = jQuery.parseJSON(res); |
| 496 | jQuery(".form-loader-count").css("width","0%"); |
| 497 | if (res.status == '1') { |
| 498 | if(res.marked == '1') { |
| 499 | jQuery("#wcp_folder_"+res.id).addClass("is-high"); |
| 500 | } else { |
| 501 | jQuery("#wcp_folder_"+res.id).removeClass("is-high"); |
| 502 | } |
| 503 | } |
| 504 | add_menu_to_list(); |
| 505 | } |
| 506 | }); |
| 507 | }); |
| 508 | }); |
| 509 | |
| 510 | /* Add new folder */ |
| 511 | jQuery(".new-folder").livequery(function(){ |
| 512 | jQuery(this).click(function(e) { |
| 513 | e.stopPropagation(); |
| 514 | jQuery(".active-menu").removeClass("active-menu"); |
| 515 | fileFolderID = jQuery(this).closest("li.route").data("folder-id"); |
| 516 | jQuery(".dynamic-menu").remove(); |
| 517 | jQuery(".active-menu").removeClass("active-menu"); |
| 518 | addFolder(); |
| 519 | add_menu_to_list(); |
| 520 | }); |
| 521 | }); |
| 522 | |
| 523 | jQuery(".cancel-button").livequery(function(){ |
| 524 | jQuery(this).click(function(e){ |
| 525 | e.stopPropagation(); |
| 526 | jQuery(".form-li").remove(); |
| 527 | }); |
| 528 | }); |
| 529 | |
| 530 | |
| 531 | |
| 532 | jQuery("#add-new-folder").livequery(function(){ |
| 533 | jQuery(this).click(function() { |
| 534 | if(jQuery("#custom-menu li.active-item").length) { |
| 535 | fileFolderID = jQuery("#custom-menu li.active-item").data("folder-id"); |
| 536 | } else { |
| 537 | fileFolderID = 0; |
| 538 | } |
| 539 | addFolder(); |
| 540 | add_menu_to_list(); |
| 541 | }); |
| 542 | }); |
| 543 | |
| 544 | jQuery("#inline-update").click(function(){ |
| 545 | if(jQuery("#custom-menu li.active-item").length) { |
| 546 | fileFolderID = jQuery("#custom-menu li.active-item").data("folder-id"); |
| 547 | updateFolder(); |
| 548 | add_menu_to_list(); |
| 549 | } |
| 550 | }); |
| 551 | |
| 552 | jQuery("#inline-remove").click(function(){ |
| 553 | if(jQuery("#custom-menu li.active-item").length) { |
| 554 | fileFolderID = jQuery("#custom-menu li.active-item").data("folder-id"); |
| 555 | jQuery(".dynamic-menu").remove(); |
| 556 | jQuery(".active-menu").removeClass("active-menu"); |
| 557 | Swal.fire({ |
| 558 | url: wcp_settings.ajax_url, |
| 559 | title: 'Are you sure you want to delete the selected folder?', |
| 560 | text: 'Items in the folder will not be deleted.', |
| 561 | type: 'warning', |
| 562 | showCancelButton: true, |
| 563 | confirmButtonText: 'Yes, delete it!', |
| 564 | cancelButtonText: 'No, keep it', |
| 565 | }).then((result) => { |
| 566 | if (result.value) { |
| 567 | Swal({ |
| 568 | title: 'Please wait..', |
| 569 | imageUrl: wcp_settings.ajax_image, |
| 570 | imageAlt: 'The uploaded picture', |
| 571 | showConfirmButton: false |
| 572 | }); |
| 573 | jQuery.ajax({ |
| 574 | url: wcp_settings.ajax_url, |
| 575 | data: "type=" + wcp_settings.post_type + "&action=wcp_remove_folder&term_id=" + fileFolderID, |
| 576 | method: 'post', |
| 577 | success: function (res) { |
| 578 | Swal.fire( |
| 579 | 'Deleted!', |
| 580 | 'Your folder has been deleted.', |
| 581 | 'success' |
| 582 | ); |
| 583 | res = jQuery.parseJSON(res); |
| 584 | if (res.status == '1') { |
| 585 | jQuery("#wcp_folder_"+fileFolderID).remove(); |
| 586 | jQuery("#folder_"+fileFolderID).remove(); |
| 587 | isKeyActive = parseInt(res.is_key_active); |
| 588 | totalFolders = parseInt(res.folders); |
| 589 | jQuery("#current-folder").text(totalFolders); |
| 590 | if(totalFolders > folderLimitation) { |
| 591 | folderLimitation = totalFolders; |
| 592 | } |
| 593 | jQuery("#total-folder").text(folderLimitation); |
| 594 | add_menu_to_list(); |
| 595 | } |
| 596 | } |
| 597 | }); |
| 598 | } |
| 599 | }); |
| 600 | } |
| 601 | }); |
| 602 | |
| 603 | jQuery('.space').livequery(function(){ |
| 604 | jQuery(this).sortable({ |
| 605 | placeholder: "ui-state-highlight", |
| 606 | connectWith:'.space', |
| 607 | tolerance:'intersect', |
| 608 | over:function(event,ui){ |
| 609 | |
| 610 | }, |
| 611 | update: function( event, ui ) { |
| 612 | thisId = ui.item.context.attributes['data-folder-id'].nodeValue; |
| 613 | orderString = ""; |
| 614 | jQuery(this).children().each(function(){ |
| 615 | if(jQuery(this).hasClass("route")) { |
| 616 | orderString += jQuery(this).data("folder-id")+","; |
| 617 | } |
| 618 | }); |
| 619 | if(orderString != "") { |
| 620 | jQuery(".form-loader-count").css("width","100%"); |
| 621 | jQuery.ajax({ |
| 622 | url: wcp_settings.ajax_url, |
| 623 | data: "term_ids=" + orderString + "&action=wcp_save_folder_order&&type=" + wcp_settings.post_type, |
| 624 | method: 'post', |
| 625 | success: function (res) { |
| 626 | res = jQuery.parseJSON(res); |
| 627 | if (res.status == '1') { |
| 628 | jQuery("#wcp_folder_parent").html(res.options); |
| 629 | jQuery(".form-loader-count").css("width","0"); |
| 630 | add_menu_to_list(); |
| 631 | } |
| 632 | } |
| 633 | }); |
| 634 | } |
| 635 | }, |
| 636 | receive:function(event, ui){ |
| 637 | calcWidth(jQuery(this).siblings('.title')); |
| 638 | check_for_sub_menu(); |
| 639 | jQuery(this).closest("li.route").addClass("active"); |
| 640 | jQuery(this).closest("li.route").find("ul.ui-sortable:first-child > li").slideDown(); |
| 641 | parentId = jQuery(this).closest("li.route").data("folder-id"); |
| 642 | thisId = ui.item.context.attributes['data-folder-id'].nodeValue; |
| 643 | if(parentId == undefined) { |
| 644 | parentId = 0; |
| 645 | } |
| 646 | orderString = ""; |
| 647 | if(jQuery("#wcp_folder_"+parentId+" .ui-sortable li").length) { |
| 648 | jQuery("#wcp_folder_"+parentId+" .ui-sortable li").each(function(){ |
| 649 | orderString += jQuery(this).data("folder-id")+","; |
| 650 | }); |
| 651 | } else if(parentId == 0) { |
| 652 | jQuery("#custom-menu > ul.space > li").each(function(){ |
| 653 | orderString += jQuery(this).data("folder-id")+","; |
| 654 | }); |
| 655 | } |
| 656 | jQuery(".form-loader-count").css("width","100%"); |
| 657 | jQuery.ajax({ |
| 658 | url: wcp_settings.ajax_url, |
| 659 | data: "term_id=" + thisId + "&action=wcp_update_parent_information&parent_id=" + parentId+"&type=" + wcp_settings.post_type, |
| 660 | method: 'post', |
| 661 | success: function (res) { |
| 662 | jQuery(".form-loader-count").css("width","0%"); |
| 663 | add_menu_to_list(); |
| 664 | } |
| 665 | }); |
| 666 | } |
| 667 | }); |
| 668 | jQuery(this).disableSelection(); |
| 669 | }); |
| 670 | jQuery(".update-inline-record").livequery(function(){ |
| 671 | jQuery(this).click(function(e){ |
| 672 | e.stopPropagation(); |
| 673 | isHigh = jQuery(this).closest("li.route").hasClass("is-high"); |
| 674 | jQuery(".dynamic-menu").remove(); |
| 675 | jQuery(".active-menu").removeClass("active-menu"); |
| 676 | menuHtml = "<div class='dynamic-menu'><ul>" + |
| 677 | "<li class='new-folder'><a href='javascript:;'><span class='folder-icon-create_new_folder'></span> New Folder</a></li>" + |
| 678 | "<li class='rename-folder'><a href='javascript:;'><span class='folder-icon-border_color'><span class='path1'></span><span class='path2'></span></span> Rename</a></li>" + |
| 679 | "<li class='mark-folder'><a href='javascript:;'><span class='folder-icon-star_rate'></span>" + ((isHigh) ? " Remove Star" : "Add a Star") + "</a></li>" + |
| 680 | "<li class='remove-folder'><a href='javascript:;'><span class='folder-icon-delete'></span> Delete</a></li>" + |
| 681 | "</ul></div>"; |
| 682 | jQuery(this).closest("h3.title").after(menuHtml); |
| 683 | jQuery(this).parents("li.route").addClass("active-menu"); |
| 684 | }); |
| 685 | }); |
| 686 | //check_for_sub_menu(); |
| 687 | //jQuery(".has-sub-tree:first").addClass("active"); |
| 688 | jQuery(".nav-icon").livequery(function(){ |
| 689 | jQuery(this).click(function(){ |
| 690 | if(jQuery(this).closest("li.route").hasClass("active")) { |
| 691 | jQuery(this).closest("li.route").removeClass("active"); |
| 692 | jQuery(this).closest("li.route").find("ul.ui-sortable:first-child > li").slideUp(); |
| 693 | folderStatus = 0; |
| 694 | } else { |
| 695 | jQuery(this).closest("li.route").addClass("active"); |
| 696 | jQuery(this).closest("li.route").find("ul.ui-sortable:first-child > li").slideDown(); |
| 697 | folderStatus = 1; |
| 698 | } |
| 699 | folderID = jQuery(this).closest("li.route").data("folder-id"); |
| 700 | jQuery(".form-loader-count").css("width","100%"); |
| 701 | checkForExpandCollapse(); |
| 702 | jQuery.ajax({ |
| 703 | url: wcp_settings.ajax_url, |
| 704 | data: "is_active=" + folderStatus + "&action=save_wcp_folder_state&term_id=" + folderID, |
| 705 | method: 'post', |
| 706 | success: function (res) { |
| 707 | jQuery(".form-loader-count").css("width","0"); |
| 708 | add_menu_to_list(); |
| 709 | } |
| 710 | }); |
| 711 | }); |
| 712 | }); |
| 713 | jQuery("#custom-menu .ui-icon, #custom-menu h3").livequery(function(){ |
| 714 | jQuery(this).click(function(){ |
| 715 | jQuery("#custom-menu .active-item").removeClass("active-item"); |
| 716 | jQuery(this).closest(".route").addClass("active-item"); |
| 717 | add_menu_to_list(); |
| 718 | }); |
| 719 | }); |
| 720 | jQuery(".remove-folder").livequery(function(){ |
| 721 | jQuery(this).click(function() { |
| 722 | folderID = jQuery(this).closest("li.route").data("folder-id"); |
| 723 | fileFolderID = folderID; |
| 724 | jQuery(".dynamic-menu").remove(); |
| 725 | jQuery(".active-menu").removeClass("active-menu"); |
| 726 | Swal.fire({ |
| 727 | url: wcp_settings.ajax_url, |
| 728 | title: 'Are you sure you want to delete the selected folder?', |
| 729 | text: 'Items in the folder will not be deleted.', |
| 730 | type: 'warning', |
| 731 | showCancelButton: true, |
| 732 | confirmButtonText: 'Yes, delete it!', |
| 733 | cancelButtonText: 'No, keep it', |
| 734 | }).then((result) => { |
| 735 | if (result.value) { |
| 736 | Swal({ |
| 737 | title: 'Please wait..', |
| 738 | imageUrl: wcp_settings.ajax_image, |
| 739 | imageAlt: 'The uploaded picture', |
| 740 | showConfirmButton: false |
| 741 | }); |
| 742 | jQuery.ajax({ |
| 743 | url: wcp_settings.ajax_url, |
| 744 | data: "type=" + wcp_settings.post_type + "&action=wcp_remove_folder&term_id=" + folderID, |
| 745 | method: 'post', |
| 746 | success: function (res) { |
| 747 | Swal.fire( |
| 748 | 'Deleted!', |
| 749 | 'Your folder has been deleted.', |
| 750 | 'success' |
| 751 | ); |
| 752 | res = jQuery.parseJSON(res); |
| 753 | if (res.status == '1') { |
| 754 | jQuery("#wcp_folder_"+fileFolderID).remove(); |
| 755 | jQuery("#folder_"+fileFolderID).remove(); |
| 756 | isKeyActive = parseInt(res.is_key_active); |
| 757 | totalFolders = parseInt(res.folders); |
| 758 | jQuery("#current-folder").text(totalFolders); |
| 759 | if(totalFolders > folderLimitation) { |
| 760 | folderLimitation = totalFolders; |
| 761 | } |
| 762 | jQuery("#total-folder").text(folderLimitation); |
| 763 | add_menu_to_list(); |
| 764 | } |
| 765 | } |
| 766 | }); |
| 767 | } |
| 768 | }); |
| 769 | }); |
| 770 | }); |
| 771 | jQuery(".wcp-parent .fa-caret-right").livequery(function(){ |
| 772 | jQuery(this).click(function() { |
| 773 | autoStatus = 1; |
| 774 | if (jQuery(this).closest(".wcp-parent").hasClass("active")) { |
| 775 | jQuery(this).closest(".wcp-parent").removeClass("active"); |
| 776 | jQuery("#custom-menu").removeClass("active"); |
| 777 | autoStatus = 0; |
| 778 | } else { |
| 779 | jQuery(this).closest(".wcp-parent").addClass("active"); |
| 780 | jQuery("#custom-menu").addClass("active"); |
| 781 | } |
| 782 | jQuery(".form-loader-count").css("width","100%"); |
| 783 | add_menu_to_list(); |
| 784 | jQuery.ajax({ |
| 785 | url: wcp_settings.ajax_url, |
| 786 | data: "type=" + wcp_settings.post_type + "&action=wcp_save_parent_data&is_active=" + autoStatus, |
| 787 | method: 'post', |
| 788 | success: function (res) { |
| 789 | jQuery(".form-loader-count").css("width","0%"); |
| 790 | } |
| 791 | }); |
| 792 | }); |
| 793 | }); |
| 794 | |
| 795 | checkForExpandCollapse(); |
| 796 | }) |
| 797 | |
| 798 | function checkForExpandCollapse() { |
| 799 | add_menu_to_list(); |
| 800 | currentStatus = true; |
| 801 | if((jQuery("#custom-menu .has-sub-tree").length == jQuery("#custom-menu .has-sub-tree.active").length) && jQuery("#custom-menu .has-sub-tree").length) { |
| 802 | jQuery("#expand-collapse-list").addClass("all-open"); |
| 803 | } else { |
| 804 | jQuery("#expand-collapse-list").removeClass("all-open"); |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | function check_for_sub_menu() { |
| 809 | jQuery("#custom-menu li.route").removeClass("has-sub-tree"); |
| 810 | jQuery("#custom-menu li.route").each(function(){ |
| 811 | if(jQuery(this).find("ul.ui-sortable li").length) { |
| 812 | jQuery(this).addClass("has-sub-tree"); |
| 813 | if(jQuery(this).find("ul.ui-sortable:first").is(":hidden")) { |
| 814 | jQuery(this).removeClass("is-hidden"); |
| 815 | } else { |
| 816 | jQuery(this).addClass("is-hidden") |
| 817 | } |
| 818 | } else { |
| 819 | jQuery(this).removeClass("active"); |
| 820 | } |
| 821 | }); |
| 822 | } |
| 823 | |
| 824 | //recursively calculate the Width all titles |
| 825 | function calcWidth(obj){ |
| 826 | var titles = |
| 827 | jQuery(obj).siblings('.space').children('.route').children('.title'); |
| 828 | jQuery(titles).each(function(index, element){ |
| 829 | var pTitleWidth = parseInt(jQuery(obj).css('width')); |
| 830 | var leftOffset = parseInt(jQuery(obj).siblings('.space').css('margin-left')); |
| 831 | var newWidth = pTitleWidth - leftOffset; |
| 832 | if (jQuery(obj).attr('id') == 'title_0'){ |
| 833 | newWidth = newWidth - 10; |
| 834 | } |
| 835 | jQuery(element).css({ |
| 836 | 'width': newWidth |
| 837 | }); |
| 838 | calcWidth(element); |
| 839 | }); |
| 840 | |
| 841 | } |