Plugin Directory

Changeset 1995336


Ignore:
Timestamp:
12/15/2018 08:26:08 AM (7 years ago)
Author:
gtekelis
Message:

code cleanup - 2018-12-15

File:
1 edited

Legend:

Unmodified
Added
Removed
  • interactive-page-hierarchy/trunk/js/gtek_iph_manager.js

    r1995332 r1995336  
    1 jQuery(document).ready(function() {
     1jQuery(document).ready(function () {
    22    toastr.options = {
    33        "closeButton": !1,
     
    5050                }
    5151            }),
    52             validateConnection: function(cellViewS, magnetS, cellViewT, magnetT, end, linkView) {
     52            validateConnection: function (cellViewS, magnetS, cellViewT, magnetT, end, linkView) {
    5353                if (magnetS && magnetS.getAttribute('port-group') === 'in') return !1;
    5454                if (cellViewS === cellViewT) return !1;
    5555                return magnetT && magnetT.getAttribute('port-group') === 'in'
    5656            },
    57             validateMagnet: function(cellView, magnet) {
     57            validateMagnet: function (cellView, magnet) {
    5858                return magnet.getAttribute('magnet') !== 'passive'
    5959            }
     
    7272        }
    7373        resizeCanvas();
    74         jQuery(window).resize(function() {
     74        jQuery(window).resize(function () {
    7575            resizeCanvas()
    7676        })
    7777    }
    7878    setUp();
    79     let sentenceWrapped = function(sentence, lineSize, maxSize) {
     79    let sentenceWrapped = function (sentence, lineSize, maxSize) {
    8080        let descriptionTrim = "";
    8181        if (sentence.length + 3 > maxSize) {
     
    9494        return splitArray
    9595    }
    96    
    97    
    98    
     96
     97
     98
    9999    let hierarchyData = [];
    100100
     
    102102    function LoadPages() {
    103103        let data = null;
    104        
     104
    105105        jQuery.post(ajaxurl, {
    106106            'action': 'gtek_iph_load_wp_pages'
    107         }, function(response) {
     107        }, function (response) {
    108108            data = JSON.parse(response.substring(0, response.length - 1));
    109            
     109
    110110            for (let i = 0; i < data.length; i++) {
    111111                let item = data[i];
     
    119119                    }
    120120                }
    121                
     121
    122122                jQuery.post(ajaxurl, {
    123123                    'action': 'iph_get_page_links',
    124124                    'id': item.ID
    125                 }, function(response) {
     125                }, function (response) {
    126126                    let responseArray = JSON.parse(response.substring(0, response.length - 1));
    127127                    let page = new joint.shapes.devs.Model({
     
    187187                    page.isChild = item.post_parent == 0 ? !1 : !0;
    188188                    page.parentNodeId = null;
    189                     hierarchyData.push(page);                   
     189                    hierarchyData.push(page);
    190190                    page.addTo(graph)
    191                    
    192                     if(hierarchyData.length == data.length){                   
     191
     192                    if (hierarchyData.length == data.length) {
    193193                        CreatePagesHierarchy();
    194194                    }
    195                    
    196                    
    197                 })//end second ajax
    198                
    199             }//end for loop
    200            
     195
     196                })//end second ajax               
     197            }//end for loop           
    201198
    202199        })//end first ajax
     
    205202
    206203    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'
    234227                        }
    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    }
    245237
    246238    let data = null;
    247239
    248 
    249 
    250     jQuery("body").bind("click", function() {
     240    jQuery("body").bind("click", function () {
    251241        data = null;
    252242        jQuery.post(ajaxurl, {
    253243            'action': 'gtek_iph_load_wp_pages'
    254         }, function(response) {
     244        }, function (response) {
    255245            data = JSON.parse(response.substring(0, response.length - 1))
    256246        })
    257247    });
    258     jQuery('#iph-newPage').on('click', function() {
     248    jQuery('#iph-newPage').on('click', function () {
    259249        let page = new joint.shapes.devs.Model({
    260250            position: {
     
    317307    });
    318308    let selectedNode = null;
    319     paper.on('cell:pointerdown', function(cellView, evt, x, y) {
     309    paper.on('cell:pointerdown', function (cellView, evt, x, y) {
    320310        selectedNode = hierarchyData.filter(item => item.id == cellView.model.id)
    321311    });
    322     jQuery('#iph-modal-save').on('click', function() {
     312    jQuery('#iph-modal-save').on('click', function () {
    323313        let sentenceWrappedTextArray = sentenceWrapped(jQuery('#pageTitle').val(), 15, 45);
    324314        let finalWrappedText = '';
     
    331321        jQuery('*[model-id="' + selectedNode[0].id + '"]').find('text.label').html(finalWrappedText)
    332322    });
    333     paper.on('link:connect', function(evt, cellView, magnet, arrowhead) {
     323    paper.on('link:connect', function (evt, cellView, magnet, arrowhead) {
    334324        let parent = hierarchyData.filter(node => node.id == evt.sourceView.model.id);
    335325        evt.targetView.model.parentNodeId = evt.sourceView.model.id;
     
    340330        }, 500)
    341331    });
    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) {
    344334        if (cell.isLink()) {
    345335            if (cell.attributes.target.id != undefined) {
     
    358348        }
    359349    });
    360     jQuery(document).on("click", ".Action_Modal", function(event) {
     350    jQuery(document).on("click", ".Action_Modal", function (event) {
    361351        event.preventDefault();
    362352        if (selectedNode[0] != undefined) {
     
    366356    });
    367357    let nodeToRemove = null;
    368     jQuery(document).on("click", ".Action_DeletePage", function(event) {
     358    jQuery(document).on("click", ".Action_DeletePage", function (event) {
    369359        event.preventDefault();
    370360        nodeToRemove = jQuery(this).closest('.joint-cell');
     
    373363        }
    374364    });
    375     jQuery(document).on("click", ".DeletePageModalButton", function(event) {
     365    jQuery(document).on("click", ".DeletePageModalButton", function (event) {
    376366        nodeToRemove.remove();
    377367        nodeToRemove = null;
     
    387377                        'action': 'iph_delete_post',
    388378                        'id': parseInt(selectedNode[0].wpPageId)
    389                     }, function(response) {})
     379                    }, function (response) { })
    390380                }
    391381            }
     
    395385                    'action': 'iph_delete_post',
    396386                    '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) {
    399389                        return n.wpPageId != selectedNode[0].wpPageId
    400390                    })
     
    410400    let contextMenuY = 0;
    411401    let contextMenuX = 0;
    412     paper.on('blank:contextmenu', function(evt, x, y) {
     402    paper.on('blank:contextmenu', function (evt, x, y) {
    413403        contextMenuX = x;
    414404        contextMenuY = y;
    415405        jQuery('#iph-newPage').trigger("click")
    416406    });
    417     jQuery('#iph-save').on('click', function(event) {
     407    jQuery('#iph-save').on('click', function (event) {
    418408        saveHierarchy('btn_save')
    419409    });
    420410    async function saveHierarchy(caller) {
    421         let promise = new Promise(function(resolve, reject) {
     411        let promise = new Promise(function (resolve, reject) {
    422412            if (caller == 'btn_save') {
    423413                jQuery('#ModalSaveOverlay').modal('show')
     
    429419                        'action': 'iph_save_pages',
    430420                        'postTitle': element.pageTitle
    431                     }, function(response) {
     421                    }, function (response) {
    432422                        element.wpPageId = parseInt(response.substring(0, response.length - 1))
    433423                    })
     
    449439                        'postParent': parentWpPageId,
    450440                        'id': element.wpPageId
    451                     }, function(response) {})
     441                    }, function (response) { })
    452442                } else if (!element.isChild && element.parentNodeId == null && element.wpPageId != null) {
    453443                    jQuery.post(ajaxurl, {
     
    456446                        'postParent': 0,
    457447                        'id': element.wpPageId
    458                     }, function(response) {
     448                    }, function (response) {
    459449                        if (caller == 'btn_save') {
    460450                            toastr.success('successfully saved');
Note: See TracChangeset for help on using the changeset viewer.