Changeset 1995336
- Timestamp:
- 12/15/2018 08:26:08 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
interactive-page-hierarchy/trunk/js/gtek_iph_manager.js
r1995332 r1995336 1 jQuery(document).ready(function () {1 jQuery(document).ready(function () { 2 2 toastr.options = { 3 3 "closeButton": !1, … … 50 50 } 51 51 }), 52 validateConnection: function (cellViewS, magnetS, cellViewT, magnetT, end, linkView) {52 validateConnection: function (cellViewS, magnetS, cellViewT, magnetT, end, linkView) { 53 53 if (magnetS && magnetS.getAttribute('port-group') === 'in') return !1; 54 54 if (cellViewS === cellViewT) return !1; 55 55 return magnetT && magnetT.getAttribute('port-group') === 'in' 56 56 }, 57 validateMagnet: function (cellView, magnet) {57 validateMagnet: function (cellView, magnet) { 58 58 return magnet.getAttribute('magnet') !== 'passive' 59 59 } … … 72 72 } 73 73 resizeCanvas(); 74 jQuery(window).resize(function () {74 jQuery(window).resize(function () { 75 75 resizeCanvas() 76 76 }) 77 77 } 78 78 setUp(); 79 let sentenceWrapped = function (sentence, lineSize, maxSize) {79 let sentenceWrapped = function (sentence, lineSize, maxSize) { 80 80 let descriptionTrim = ""; 81 81 if (sentence.length + 3 > maxSize) { … … 94 94 return splitArray 95 95 } 96 97 98 96 97 98 99 99 let hierarchyData = []; 100 100 … … 102 102 function LoadPages() { 103 103 let data = null; 104 104 105 105 jQuery.post(ajaxurl, { 106 106 'action': 'gtek_iph_load_wp_pages' 107 }, function (response) {107 }, function (response) { 108 108 data = JSON.parse(response.substring(0, response.length - 1)); 109 109 110 110 for (let i = 0; i < data.length; i++) { 111 111 let item = data[i]; … … 119 119 } 120 120 } 121 121 122 122 jQuery.post(ajaxurl, { 123 123 'action': 'iph_get_page_links', 124 124 'id': item.ID 125 }, function (response) {125 }, function (response) { 126 126 let responseArray = JSON.parse(response.substring(0, response.length - 1)); 127 127 let page = new joint.shapes.devs.Model({ … … 187 187 page.isChild = item.post_parent == 0 ? !1 : !0; 188 188 page.parentNodeId = null; 189 hierarchyData.push(page); 189 hierarchyData.push(page); 190 190 page.addTo(graph) 191 192 if (hierarchyData.length == data.length){191 192 if (hierarchyData.length == data.length) { 193 193 CreatePagesHierarchy(); 194 194 } 195 196 197 })//end second ajax 198 199 }//end for loop 200 195 196 })//end second ajax 197 }//end for loop 201 198 202 199 })//end first ajax … … 205 202 206 203 function CreatePagesHierarchy() { 207 console.log(hierarchyData.length); 208 209 //setTimeout(() => { 210 211 for (let i = 0; i < hierarchyData.length; i++) { 212 let element = hierarchyData[i]; 213 if (element.parentWpPageId > 0) { 214 let parentNodeObject = hierarchyData.find(function(item) { 215 return item.wpPageId == element.parentWpPageId 216 }); 217 let parentNodeId = parentNodeObject.id; 218 element.parentNodeId = parentNodeObject.id; 219 parentNodeObject.children.push(parseInt(element.wpPageId)); 220 let link = new joint.dia.Link({ 221 source: { 222 id: parentNodeId, 223 port: 'out' 224 }, 225 target: { 226 id: element.id, 227 port: 'in' 228 }, 229 attrs: { 230 '.connection': { 231 'stroke-width': 2, 232 stroke: '#a8a8a8' 233 } 204 205 for (let i = 0; i < hierarchyData.length; i++) { 206 let element = hierarchyData[i]; 207 if (element.parentWpPageId > 0) { 208 let parentNodeObject = hierarchyData.find(function (item) { 209 return item.wpPageId == element.parentWpPageId 210 }); 211 let parentNodeId = parentNodeObject.id; 212 element.parentNodeId = parentNodeObject.id; 213 parentNodeObject.children.push(parseInt(element.wpPageId)); 214 let link = new joint.dia.Link({ 215 source: { 216 id: parentNodeId, 217 port: 'out' 218 }, 219 target: { 220 id: element.id, 221 port: 'in' 222 }, 223 attrs: { 224 '.connection': { 225 'stroke-width': 2, 226 stroke: '#a8a8a8' 234 227 } 235 }); 236 graph.addCells([link]) 237 } 238 } 239 joint.layout.DirectedGraph.layout(graph, { 240 setLinkVertices: !1 241 }) 242 // }, 2000) 243 } 244 //CreatePagesHierarchy(); 228 } 229 }); 230 graph.addCells([link]) 231 } 232 } 233 joint.layout.DirectedGraph.layout(graph, { 234 setLinkVertices: !1 235 }) 236 } 245 237 246 238 let data = null; 247 239 248 249 250 jQuery("body").bind("click", function() { 240 jQuery("body").bind("click", function () { 251 241 data = null; 252 242 jQuery.post(ajaxurl, { 253 243 'action': 'gtek_iph_load_wp_pages' 254 }, function (response) {244 }, function (response) { 255 245 data = JSON.parse(response.substring(0, response.length - 1)) 256 246 }) 257 247 }); 258 jQuery('#iph-newPage').on('click', function () {248 jQuery('#iph-newPage').on('click', function () { 259 249 let page = new joint.shapes.devs.Model({ 260 250 position: { … … 317 307 }); 318 308 let selectedNode = null; 319 paper.on('cell:pointerdown', function (cellView, evt, x, y) {309 paper.on('cell:pointerdown', function (cellView, evt, x, y) { 320 310 selectedNode = hierarchyData.filter(item => item.id == cellView.model.id) 321 311 }); 322 jQuery('#iph-modal-save').on('click', function () {312 jQuery('#iph-modal-save').on('click', function () { 323 313 let sentenceWrappedTextArray = sentenceWrapped(jQuery('#pageTitle').val(), 15, 45); 324 314 let finalWrappedText = ''; … … 331 321 jQuery('*[model-id="' + selectedNode[0].id + '"]').find('text.label').html(finalWrappedText) 332 322 }); 333 paper.on('link:connect', function (evt, cellView, magnet, arrowhead) {323 paper.on('link:connect', function (evt, cellView, magnet, arrowhead) { 334 324 let parent = hierarchyData.filter(node => node.id == evt.sourceView.model.id); 335 325 evt.targetView.model.parentNodeId = evt.sourceView.model.id; … … 340 330 }, 500) 341 331 }); 342 paper.on('link:pointerup', function (evt, cellView, magnet, arrowhead) {});343 graph.on('remove', function (cell, collection, opt) {332 paper.on('link:pointerup', function (evt, cellView, magnet, arrowhead) { }); 333 graph.on('remove', function (cell, collection, opt) { 344 334 if (cell.isLink()) { 345 335 if (cell.attributes.target.id != undefined) { … … 358 348 } 359 349 }); 360 jQuery(document).on("click", ".Action_Modal", function (event) {350 jQuery(document).on("click", ".Action_Modal", function (event) { 361 351 event.preventDefault(); 362 352 if (selectedNode[0] != undefined) { … … 366 356 }); 367 357 let nodeToRemove = null; 368 jQuery(document).on("click", ".Action_DeletePage", function (event) {358 jQuery(document).on("click", ".Action_DeletePage", function (event) { 369 359 event.preventDefault(); 370 360 nodeToRemove = jQuery(this).closest('.joint-cell'); … … 373 363 } 374 364 }); 375 jQuery(document).on("click", ".DeletePageModalButton", function (event) {365 jQuery(document).on("click", ".DeletePageModalButton", function (event) { 376 366 nodeToRemove.remove(); 377 367 nodeToRemove = null; … … 387 377 'action': 'iph_delete_post', 388 378 'id': parseInt(selectedNode[0].wpPageId) 389 }, function (response) {})379 }, function (response) { }) 390 380 } 391 381 } … … 395 385 'action': 'iph_delete_post', 396 386 'id': parseInt(selectedNode[0].wpPageId) 397 }, function (response) {398 let remainingPages = _.remove(hierarchyData, function (n) {387 }, function (response) { 388 let remainingPages = _.remove(hierarchyData, function (n) { 399 389 return n.wpPageId != selectedNode[0].wpPageId 400 390 }) … … 410 400 let contextMenuY = 0; 411 401 let contextMenuX = 0; 412 paper.on('blank:contextmenu', function (evt, x, y) {402 paper.on('blank:contextmenu', function (evt, x, y) { 413 403 contextMenuX = x; 414 404 contextMenuY = y; 415 405 jQuery('#iph-newPage').trigger("click") 416 406 }); 417 jQuery('#iph-save').on('click', function (event) {407 jQuery('#iph-save').on('click', function (event) { 418 408 saveHierarchy('btn_save') 419 409 }); 420 410 async function saveHierarchy(caller) { 421 let promise = new Promise(function (resolve, reject) {411 let promise = new Promise(function (resolve, reject) { 422 412 if (caller == 'btn_save') { 423 413 jQuery('#ModalSaveOverlay').modal('show') … … 429 419 'action': 'iph_save_pages', 430 420 'postTitle': element.pageTitle 431 }, function (response) {421 }, function (response) { 432 422 element.wpPageId = parseInt(response.substring(0, response.length - 1)) 433 423 }) … … 449 439 'postParent': parentWpPageId, 450 440 'id': element.wpPageId 451 }, function (response) {})441 }, function (response) { }) 452 442 } else if (!element.isChild && element.parentNodeId == null && element.wpPageId != null) { 453 443 jQuery.post(ajaxurl, { … … 456 446 'postParent': 0, 457 447 'id': element.wpPageId 458 }, function (response) {448 }, function (response) { 459 449 if (caller == 'btn_save') { 460 450 toastr.success('successfully saved');
Note: See TracChangeset
for help on using the changeset viewer.