<commit_before><script>
    var processNames = [];
    var processListObj;

    window.onload = getProcessList;

    function getMainProcess(){
        var mainProcess = $('#view-header').text() + "-" + $('#process-version').text();
        return mainProcess;
    }

    function showBPMN() {

        $("#overviewDiv").hide();
        $("#processTextContainer").hide();
        $("#processTextEditDiv").hide();
        $("#bpmnViewDiv").show();
        $("#bpmnEditDiv").hide();

        $.ajax({
            url: 'https://localhost:9443/publisher/assets/process/apis/get_bpmn_content?bpmn_content_path=/_system/governance/bpmn/{{assets.tables.[0].fields.name.value}}/{{assets.tables.[0].fields.version.value}}',
            type: 'GET',
            success: function (response) {
                var bpmnObject = JSON.parse(response);
                $("#bpmnImage").attr("src", "data:image/png;base64," + bpmnObject.bpmnImage);
            },
            error: function () {
                alertify.error('Error');
            }
        });

    }

    function viewText() {
        loadProcessText();

        $("#overviewDiv").hide();
        $("#processTextContainer").show();
        $("#processTextEditDiv").hide();
        $("#bpmnViewDiv").hide();
        $("#bpmnEditDiv").hide();
    }

    function editText() {
        $("#processContent").val($("#processTextDiv").html());
        showTextEditor();
    }

    function loadProcessText() {
        var ppath = 'apis/get_process_text?process_text_path={{assets.tables.[1].fields.processtextpath.value}}';

        $.ajax({
            url: 'https://localhost:9443/publisher/assets/process/apis/get_process_text?process_text_path=/processText/{{assets.tables.[0].fields.name.value}}/{{assets.tables.[0].fields.version.value}}',
            type: 'GET',
            success: function (response) {
                $("#processTextDiv").html(response);
            },
            error: function () {
                alertify.error('Error');
            }
        });
    }

    function saveProcessText(e) {
        var textContent = tinyMCE.get('processContent').getContent();
        if (textContent == "") {
            if($(e).attr('id') == 'processTextSaveBtn'){
                alertify.error('Process content is empty.');
            }
        } else {
            // save the process

            $.ajax({
                url: 'https://localhost:9443/publisher/assets/process/apis/save_process_text',
                type: 'POST',
                data: { 'processName': $("#textProcessName").val(), 'processVersion' : $("#textProcessVersion").val(), 'processText' : textContent},
                success: function (response) {
                    if($(e).attr('id') == 'processTextSaveBtn'){
                        alertify.success("Successfully saved the process content.");
                    }
                    $("#viewTextButton").show();
                    $("#addTextButton").hide();
                },
                error: function () {
                    alertify.error('Error');
                }
            });
        }
    }

    function showTextEditor() {
        $("#overviewDiv").hide();
        $("#processTextContainer").hide();
        $("#processTextEditDiv").show();
        $("#bpmnViewDiv").hide();
        $("#bpmnEditDiv").hide();

        tinymce.init({
            selector: "#processContent"
        });
    }

    function showBPMNUploader() {
        $("#overviewDiv").hide();
        $("#processTextContainer").hide();
        $("#processTextEditDiv").hide();
        $("#bpmnViewDiv").hide();
        $("#bpmnEditDiv").show();
    }

    function showOverview(e) {
        if($(e).attr('id') == 'processTextOverviewBtn'){
            saveProcessText(e);
        }
        $("#overviewDiv").show();
        $("#processTextContainer").hide();
        $("#processTextEditDiv").hide();
        $("#bpmnViewDiv").hide();
        $("#bpmnEditDiv").hide();
    }

    function editProcessOwner(e){
        if($(e).text() == ''){
            alertify.error('Process owner field is empty.');
        }else{
            $('#processOwnerUpdateBtn').show();
        }
    }

    function subProcessNamesAutoComplete(){
        $(".subprocess_Name").autocomplete({
            source: processNames
        });
    }

    function successorNameAutoComplete(){
        $(".successor_Name").autocomplete({
            source: processNames
        });
    }

    function predecessorNameAutoComplete(){
        $(".predecessor_Name").autocomplete({
            source: processNames
        });
    }

    function getProcessList(){
        $.ajax({
            url: 'https://localhost:9443/publisher/assets/process/apis/get_process_list',
            type: 'GET',
            success: function (response) {
                processListObj = JSON.parse(response);
                for(var i = 0 ; i < processListObj.length ; i++){
                    processNames.push(processListObj[i].processname + "-" + processListObj[i].processversion);
                }
            },
            error: function () {
                alertify.error('Error');
            }
        });
    }

    function isProcessNotAvailableInList(processName){
        for(var i = 0 ; i < processNames.length ; i++){
            if(processNames[i] == processName){
                return false;
            }
        }
        return true;
    }

    function readUpdatedSubprocess(e){
        var subprocessInput = $(e).parent().closest("tr").find("input").val();

        if(subprocessInput == ''){
            alertify.error('Field is empty.');
        }else if(isProcessNotAvailableInList(subprocessInput)){
            alertify.warning('Please enter a correct process name that already exists.');
        }else if(subprocessInput == getMainProcess()){
            alertify.warning('You cannot assign the process name as its subprocess.');
        }else{
            $(e).parent().closest("tr").find("input").replaceWith("<span id='subprocess_Name' class='subprocess_Name'>"+subprocessInput+"</span>");
            $(e).replaceWith($(e).parent().closest("tr").find("a"));
            var subprocessPath, subprocessId;
            for(var i = 0 ; i < processListObj.length ; i++){
                if(processListObj[i].processname == subprocessInput.split("-")[0] &&
                        processListObj[i].processversion == subprocessInput.split("-")[1]){
                    subprocessPath = processListObj[i].path;
                    subprocessId = processListObj[i].processid;
                    break;
                }
            }

            var subprocessInfo = {
                name: subprocessInput.split("-")[0],
                path: subprocessPath,
                id: subprocessId
            };

            var subProcessDetails = {
                'processName': $('#view-header').text(),
                'processVersion' : $('#process-version').text(),
                'subprocess' : subprocessInfo
            };

            $.ajax({
                url: 'https://localhost:9443/publisher/assets/process/apis/update_subprocess',
                type: 'POST',
                data: { 'subprocessDetails': JSON.stringify(subProcessDetails) },
                success: function (response) {
                    alertify.success('Successfully updated the subprocess details.');
                },
                error: function () {
                    alertify.error('Error');
                }
            });
        }
    }

    function readUpdatedSuccessor(e){
        var successorInput = $(e).parent().closest("tr").find("input").val();

        if(successorInput == ''){
            alertify.error('Field is empty.');
        }else if(isProcessNotAvailableInList(successorInput)){
            alertify.warning('Please enter a correct process name that already exists.');
        }else if(successorInput == getMainProcess()){
            alertify.warning('You cannot assign the process name as its successor.');
        }else{
            $(e).parent().closest("tr").find("input").replaceWith("<span id='successor_Name' class='successor_Name'>"+successorInput+"</span>");
            $(e).replaceWith($(e).parent().closest("tr").find("a"));
            var successorPath, successorId;
            for(var i = 0 ; i < processListObj.length ; i++){
                if(processListObj[i].processname == successorInput.split("-")[0] &&
                        processListObj[i].processversion == successorInput.split("-")[1]){
                    successorPath = processListObj[i].path;
                    successorId = processListObj[i].processid;
                    break;
                }
            }

            var successorInfo = {
                name: successorInput.split("-")[0],
                path: successorPath,
                id: successorId
            };

            var successorDetails = {
                'processName': $('#view-header').text(),
                'processVersion' : $('#process-version').text(),
                'successor' : successorInfo
            };

            $.ajax({
                url: 'https://localhost:9443/publisher/assets/process/apis/update_successor',
                type: 'POST',
                data: { 'successorDetails': JSON.stringify(successorDetails) },
                success: function (response) {
                    alertify.success('Successfully updated the successor details.');
                },
                error: function () {
                    alertify.error('Error');
                }
            });
        }
    }

    function readUpdatedPredecessor(e){
        var predecessorInput = $(e).parent().closest("tr").find("input").val();

        if(predecessorInput == ''){
            alertify.error('Field is empty.');
        }else if(isProcessNotAvailableInList(predecessorInput)){
            alertify.warning('Please enter correct process name that exists.');
        }else if(predecessorInput == getMainProcess()){
            alertify.warning('You cannot assign the process name as its predecessor.');
        }else{
            $(e).parent().closest("tr").find("input").replaceWith("<span id='predecessor_Name' class='predecessor_Name'>"+predecessorInput+"</span>");
            $(e).replaceWith($(e).parent().closest("tr").find("a"));
            var predecessorPath, predecessorId;
            for(var i = 0 ; i < processListObj.length ; i++){
                if(processListObj[i].processname == predecessorInput.split("-")[0] &&
                        processListObj[i].processversion == predecessorInput.split("-")[1]){
                    predecessorPath = processListObj[i].path;
                    predecessorId = processListObj[i].processid;
                    break;
                }
            }

            var predecessorInfo = {
                name: predecessorInput.split("-")[0],
                path: predecessorPath,
                id: predecessorId
            };

            var predecessorDetails = {
                'processName': $('#view-header').text(),
                'processVersion' : $('#process-version').text(),
                'predecessor' : predecessorInfo
            };

            $.ajax({
                url: 'https://localhost:9443/publisher/assets/process/apis/update_predecessor',
                type: 'POST',
                data: { 'predecessorDetails': JSON.stringify(predecessorDetails) },
                success: function (response) {
                    alertify.success('Successfully updated the predecessor details.');
                },
                error: function () {
                    alertify.error('Error');
                }
            });
        }
    }

    function deleteSubprocess(e){
        var deleteSubInput = $(e).parent().closest("tr").find("span").text();
        if(! isProcessNotAvailableInList(deleteSubInput)){
            var deleteSubPath, deleteSubId;
            for(var i = 0 ; i < processListObj.length ; i++){
                if(processListObj[i].processname == deleteSubInput.split("-")[0] &&
                        processListObj[i].processversion == deleteSubInput.split("-")[1]){
                    deleteSubPath = processListObj[i].path;
                    deleteSubId = processListObj[i].processid;
                    break;
                }
            }

            var deleteSubInfo = {
                name: deleteSubInput.split("-")[0],
                path: deleteSubPath,
                id: deleteSubId
            };

            var deleteSubObj = {
                'processName': $('#view-header').text(),
                'processVersion' : $('#process-version').text(),
                'deleteSubprocess' : deleteSubInfo
            };

            $.ajax({
                url: 'https://localhost:9443/publisher/assets/process/apis/delete_subprocess',
                type: 'POST',
                data: { 'deleteSubprocessDetails': JSON.stringify(deleteSubObj) },
                success: function (response) {
                    alertify.success('Successfully deleted the subprocess.');
                },
                error: function () {
                    alertify.error('Error');
                }
            });
        }
    }

    function deleteSuccessor(e){
        var deleteSuccessorInput = $(e).parent().closest("tr").find("span").text();
        if(! isProcessNotAvailableInList(deleteSuccessorInput)){
            var deleteSuccessorPath, deleteSuccessorId;
            for(var i = 0 ; i < processListObj.length ; i++){
                if(processListObj[i].processname == deleteSuccessorInput.split("-")[0] &&
                        processListObj[i].processversion == deleteSuccessorInput.split("-")[1]){
                    deleteSuccessorPath = processListObj[i].path;
                    deleteSuccessorId = processListObj[i].processid;
                    break;
                }
            }

            var deleteSuccessorInfo = {
                name: deleteSuccessorInput.split("-")[0],
                path: deleteSuccessorPath,
                id: deleteSuccessorId
            };

            var deleteSuccessorObj = {
                'processName': $('#view-header').text(),
                'processVersion' : $('#process-version').text(),
                'deleteSuccessor' : deleteSuccessorInfo
            };

            $.ajax({
                url: 'https://localhost:9443/publisher/assets/process/apis/delete_successor',
                type: 'POST',
                data: { 'deleteSuccessorDetails': JSON.stringify(deleteSuccessorObj) },
                success: function (response) {
                    alertify.success('Successfully deleted the successor.');
                },
                error: function () {
                    alertify.error('Error');
                }
            });
        }
    }

    function deletePredecessor(e){
        var deletePredecessorInput = $(e).parent().closest("tr").find("span").text();
        if(! isProcessNotAvailableInList(deletePredecessorInput)){
            var deletePredecessorPath, deletePredecessorId;
            for(var i = 0 ; i < processListObj.length ; i++){
                if(processListObj[i].processname == deletePredecessorInput.split("-")[0] &&
                        processListObj[i].processversion == deletePredecessorInput.split("-")[1]){
                    deletePredecessorPath = processListObj[i].path;
                    deletePredecessorId = processListObj[i].processid;
                    break;
                }
            }

            var deletePredecessorInfo = {
                name: deletePredecessorInput.split("-")[0],
                path: deletePredecessorPath,
                id: deletePredecessorId
            };

            var deletePredecessorObj = {
                'processName': $('#view-header').text(),
                'processVersion' : $('#process-version').text(),
                'deletePredecessor' : deletePredecessorInfo
            };

            $.ajax({
                url: 'https://localhost:9443/publisher/assets/process/apis/delete_Predecessor',
                type: 'POST',
                data: { 'deletePredecessorDetails': JSON.stringify(deletePredecessorObj) },
                success: function (response) {
                    alertify.success('Successfully deleted the Predecessor.');
                },
                error: function () {
                    alertify.error('Error');
                }
            });
        }
    }

    function updateProcessOwner(e){
        var processOwner = $(e).parent().closest("tr").find("td:eq(1)").text();
        if(processOwner == ''){
            alertify.error('Field is empty.');
        }else{
            var ownerDetails = {
                'processName': $('#view-header').text(),
                'processVersion' : $('#process-version').text(),
                'processOwner' : processOwner
            };

            $.ajax({
                url: 'https://localhost:9443/publisher/assets/process/apis/update_owner',
                type: 'POST',
                data: { 'ownerDetails': JSON.stringify(ownerDetails) },
                success: function (response) {
                    $(e).hide();
                    alertify.success('Successfully updated the Process owner name.');
                },
                error: function () {
                    alertify.error('Error');
                }
            });
        }
    }

    function isInputFieldEmpty(tableName){
        var isFieldEmpty = false;
        $('#table_' + tableName + ' tbody tr').each(function(){
            if($(this).find('td:eq(0) input').val() == ''){
                isFieldEmpty = true;
            }
        });
        return isFieldEmpty;
    }

    function addUnboundedRow(e){
        var tableName = $(e).attr('data-name');
        var table = $('#table_'+tableName);

        if(! isInputFieldEmpty(tableName)) {
            var referenceRow = $('#table_reference_' + tableName);
            var newRow = referenceRow.clone().removeAttr('id');
            $('input[type="text"]', newRow).val('');
            table.show().append(newRow);
        }else{
            alertify.error('Please fill the empty ' + tableName + ' field.');
        }
    }

</script>

<h2 id="view-header">{{assets.tables.[0].fields.name.value}}</h2>
<br/>
<div id="overviewDiv">
            <table class="table table-responsive" style="width: 8cm;border-bottom:0px !important;">
                <tbody>
                <tr>
                    <td width="40%" style="border: 0px !important;">Version:</td>
                    <td width="60%" id="process-version" style="border: 0px !important;">{{assets.tables.[0].fields.version.value}}</td>
                </tr>
                <tr>
                    <td width="40%" style="border: 0px !important;">Owner:</td>
                    <td width="40%" style="border: 0px !important;" contenteditable="true" onblur="editProcessOwner(this)">{{assets.tables.[0].fields.owner.value}}</td>
                    <td width="20%" style="border: 0px !important;"><span id="processOwnerUpdateBtn" class="glyphicon glyphicon-ok" data-toggle="tooltip" title="Click here to update the value" style="color:#0081c2;cursor: pointer;display: none;" onclick="updateProcessOwner(this)"></span></td>
                </tr>
                </tbody>
            </table>

            <div class="control-group" style="display: inline-block">
                {{#if processTextAvaliable}}
                    <div id="vtdiv"><button id="viewTextButton" class="btn btn-primary" onclick="viewText()">View/Edit Process Text</button></div>
                    <div id="atdiv"><button id="addTextButton" class="btn btn-primary" onclick="showTextEditor()" style="display: none">Describe process in text</button></div>
                {{else}}
                    <div id="vtdiv"><button id="viewTextButton" class="btn btn-primary" onclick="viewText()" style="display: none">View/Edit Process Text</button></div>
                    <div id="atdiv"><button id="addTextButton" class="btn btn-primary" onclick="showTextEditor()">Describe process in text</button></div>
                {{/if}}
            </div>

            <div class="control-group" style="display: inline-block">
                {{#if bpmnAvaliable}}
                    <button class="btn btn-primary" onclick="showBPMN()">Show BPMN</button>
                    <!--<a href="../../bpmn/details/{{assets.tables.[1].fields.bpmnid.value}}">Show BPMN</a>-->
                {{else}}
                    <button class="btn btn-primary" onclick="showBPMNUploader()">Associate a BPMN model</button>
                {{/if}}
            </div>
            <br /><br />

    <form class="form-horizontal">
        <div class="control-group">

            <h2 class="field-title">
                <a class="collapsing-h2" aria-expanded="true" href="#subprocess" data-toggle="collapse" rel="tooltip" title="List of subprocesses for a given process">
                    <i class="cu-btn-exp-col btn-collapsed">Subprocess</i>
                </a>
            </h2>

            <div id="subprocess" class="responsive-form-container collapse in" aria-expanded="true" style="">
                <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12" style="padding:0">
                    &nbsp;
                </div>
                <div style="border:0px solid #ff0000; padding:0" class="col-lg-10 col-md-10 col-sm-12 col-xs-12">
                    <div class="add-unbounded-row"><a data-name="subprocess" onclick="addUnboundedRow(this)"><i class="fa fa-plus-circle"></i> Add Subprocess</a></div>
                    <table class="tablex cu-data-table js-unbounded-table" id="table_subprocess">
                        <thead>

                        <tr><th></th>
                        </tr></thead>
                        <tbody>
                        {{#each involveProcessList.subprocesses}}
                            <tr>
                                <td valign="top" style="width: 85%;"><span id="subprocess_Name" class="subprocess_Name">{{this.name}}-{{this.version}}</span></td>
                                <td style="width: 15%;"><a class="js-remove-row" onclick="deleteSubprocess(this)"><i class="fa fa-trash"></i></a> </td>
                            </tr>
                        {{/each}}
                        </tbody>
                    </table>
                </div>
            </div>

            <h2 class="field-title">
                <a class="collapsing-h2" aria-expanded="true" href="#successor" data-toggle="collapse" rel="tooltip" title="List of successor processes for a given process">
                    <i class="cu-btn-exp-col btn-collapsed">Successor</i>
                </a>
            </h2>
            <div id="successor" class="responsive-form-container collapse in" aria-expanded="true" style="">
                <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12" style="padding:0">
                    &nbsp;
                </div>
                <div style="border:0px solid #ff0000; padding:0" class="col-lg-10 col-md-10 col-sm-12 col-xs-12">
                    <div class="add-unbounded-row"><a data-name="successor" onclick="addUnboundedRow(this)"><i class="fa fa-plus-circle"></i> Add Successor</a></div>
                    <table class="tablex cu-data-table js-unbounded-table" id="table_successor">
                        <thead>

                        <tr><th></th>
                        </tr></thead>
                        <tbody>
                        {{#each involveProcessList.successors}}
                            <tr>
                                <td valign="top" style="width: 85%;"><span id="successor_Name" class="successor_Name">{{this.name}}-{{this.version}}</span></td>
                                <td style="width: 15%;"><a class="js-remove-row" onclick="deleteSuccessor(this)"><i class="fa fa-trash"></i></a> </td>
                            </tr>
                        {{/each}}
                        </tbody>
                    </table>
                </div>
            </div>


            <h2 class="field-title">
                <a class="collapsing-h2" aria-expanded="true" href="#predecessor" data-toggle="collapse" rel="tooltip" title="List of predecessor processes for a given process">
                    <i class="cu-btn-exp-col btn-collapsed">Predecessor</i>
                </a>
            </h2>

            <div id="predecessor" class="responsive-form-container collapse in" aria-expanded="true" style="">
                <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12" style="padding:0">
                    &nbsp;
                </div>
                <div style="border:0px solid #ff0000; padding:0" class="col-lg-10 col-md-10 col-sm-12 col-xs-12">
                    <div class="add-unbounded-row"><a data-name="predecessor" onclick="addUnboundedRow(this)"><i class="fa fa-plus-circle"></i> Add Predecessor</a></div>
                    <table class="tablex cu-data-table js-unbounded-table" id="table_predecessor">
                        <thead>

                        <tr><th></th>
                        </tr></thead>
                        <tbody>
                        {{#each involveProcessList.predecessors}}
                            <tr>
                                <td valign="top" style="width: 85%;"><span id="predecessor_Name" class="predecessor_Name">{{this.name}}-{{this.version}}</span></td>
                                <td style="width: 15%;"><a class="js-remove-row" onclick="deletePredecessor(this)"><i class="fa fa-trash"></i></a> </td>
                            </tr>
                        {{/each}}
                        </tbody>
                    </table>
                </div>
            </div>

        </div><commit_msg>align table and add the proper message texts to the alerts<commit_after><script>
    var processNames = [];
    var processListObj;

    window.onload = getProcessList;

    function getMainProcess(){
        var mainProcess = $('#view-header').text() + "-" + $('#process-version').text();
        return mainProcess;
    }

    function showBPMN() {

        $("#overviewDiv").hide();
        $("#processTextContainer").hide();
        $("#processTextEditDiv").hide();
        $("#bpmnViewDiv").show();
        $("#bpmnEditDiv").hide();

        $.ajax({
            url: 'https://localhost:9443/publisher/assets/process/apis/get_bpmn_content?bpmn_content_path=/_system/governance/bpmn/{{assets.tables.[0].fields.name.value}}/{{assets.tables.[0].fields.version.value}}',
            type: 'GET',
            success: function (response) {
                var bpmnObject = JSON.parse(response);
                $("#bpmnImage").attr("src", "data:image/png;base64," + bpmnObject.bpmnImage);
            },
            error: function () {
                alertify.error('Error');
            }
        });

    }

    function viewText() {
        loadProcessText();

        $("#overviewDiv").hide();
        $("#processTextContainer").show();
        $("#processTextEditDiv").hide();
        $("#bpmnViewDiv").hide();
        $("#bpmnEditDiv").hide();
    }

    function editText() {
        $("#processContent").val($("#processTextDiv").html());
        showTextEditor();
    }

    function loadProcessText() {
        var ppath = 'apis/get_process_text?process_text_path={{assets.tables.[1].fields.processtextpath.value}}';

        $.ajax({
            url: 'https://localhost:9443/publisher/assets/process/apis/get_process_text?process_text_path=/processText/{{assets.tables.[0].fields.name.value}}/{{assets.tables.[0].fields.version.value}}',
            type: 'GET',
            success: function (response) {
                $("#processTextDiv").html(response);
            },
            error: function () {
                alertify.error('Error');
            }
        });
    }

    function saveProcessText(e) {
        var textContent = tinyMCE.get('processContent').getContent();
        if (textContent == "") {
            if($(e).attr('id') == 'processTextSaveBtn'){
                alertify.error('Process content is empty.');
            }
        } else {
            // save the process

            $.ajax({
                url: 'https://localhost:9443/publisher/assets/process/apis/save_process_text',
                type: 'POST',
                data: { 'processName': $("#textProcessName").val(), 'processVersion' : $("#textProcessVersion").val(), 'processText' : textContent},
                success: function (response) {
                    if($(e).attr('id') == 'processTextSaveBtn'){
                        alertify.success("Successfully saved the process content.");
                    }
                    $("#viewTextButton").show();
                    $("#addTextButton").hide();
                },
                error: function () {
                    alertify.error('Error');
                }
            });
        }
    }

    function showTextEditor() {
        $("#overviewDiv").hide();
        $("#processTextContainer").hide();
        $("#processTextEditDiv").show();
        $("#bpmnViewDiv").hide();
        $("#bpmnEditDiv").hide();

        tinymce.init({
            selector: "#processContent"
        });
    }

    function showBPMNUploader() {
        $("#overviewDiv").hide();
        $("#processTextContainer").hide();
        $("#processTextEditDiv").hide();
        $("#bpmnViewDiv").hide();
        $("#bpmnEditDiv").show();
    }

    function showOverview(e) {
        if($(e).attr('id') == 'processTextOverviewBtn'){
            saveProcessText(e);
        }
        $("#overviewDiv").show();
        $("#processTextContainer").hide();
        $("#processTextEditDiv").hide();
        $("#bpmnViewDiv").hide();
        $("#bpmnEditDiv").hide();
    }

    function editProcessOwner(e){
        if($(e).text() == ''){
            alertify.error('Process owner field is empty.');
        }else{
            $('#processOwnerUpdateBtn').show();
        }
    }

    function subProcessNamesAutoComplete(){
        $(".subprocess_Name").autocomplete({
            source: processNames
        });
    }

    function successorNameAutoComplete(){
        $(".successor_Name").autocomplete({
            source: processNames
        });
    }

    function predecessorNameAutoComplete(){
        $(".predecessor_Name").autocomplete({
            source: processNames
        });
    }

    function getProcessList(){
        $.ajax({
            url: 'https://localhost:9443/publisher/assets/process/apis/get_process_list',
            type: 'GET',
            success: function (response) {
                processListObj = JSON.parse(response);
                for(var i = 0 ; i < processListObj.length ; i++){
                    processNames.push(processListObj[i].processname + "-" + processListObj[i].processversion);
                }
            },
            error: function () {
                alertify.error('Error');
            }
        });
    }

    function isProcessNotAvailableInList(processName){
        for(var i = 0 ; i < processNames.length ; i++){
            if(processNames[i] == processName){
                return false;
            }
        }
        return true;
    }

    function readUpdatedSubprocess(e){
        var subprocessInput = $(e).parent().closest("tr").find("input").val();

        if(subprocessInput == ''){
            alertify.error('Field is empty.');
        }else if(isProcessNotAvailableInList(subprocessInput)){
            alertify.warning('Please enter a correct process name that already exists.');
        }else if(subprocessInput == getMainProcess()){
            alertify.warning('You cannot assign the process name as its subprocess.');
        }else{
            $(e).parent().closest("tr").find("input").replaceWith("<span id='subprocess_Name' class='subprocess_Name'>"+subprocessInput+"</span>");
            $(e).hide();
            var subprocessPath, subprocessId;
            for(var i = 0 ; i < processListObj.length ; i++){
                if(processListObj[i].processname == subprocessInput.split("-")[0] &&
                        processListObj[i].processversion == subprocessInput.split("-")[1]){
                    subprocessPath = processListObj[i].path;
                    subprocessId = processListObj[i].processid;
                    break;
                }
            }

            var subprocessInfo = {
                name: subprocessInput.split("-")[0],
                path: subprocessPath,
                id: subprocessId
            };

            var subProcessDetails = {
                'processName': $('#view-header').text(),
                'processVersion' : $('#process-version').text(),
                'subprocess' : subprocessInfo
            };

            $.ajax({
                url: 'https://localhost:9443/publisher/assets/process/apis/update_subprocess',
                type: 'POST',
                data: { 'subprocessDetails': JSON.stringify(subProcessDetails) },
                success: function (response) {
                    alertify.success('Process ' + subprocessInput + ' successfully added to the subprocess list.');
                },
                error: function () {
                    alertify.error('Error');
                }
            });
        }
    }

    function readUpdatedSuccessor(e){
        var successorInput = $(e).parent().closest("tr").find("input").val();

        if(successorInput == ''){
            alertify.error('Field is empty.');
        }else if(isProcessNotAvailableInList(successorInput)){
            alertify.warning('Please enter a correct process name that already exists.');
        }else if(successorInput == getMainProcess()){
            alertify.warning('You cannot assign the process name as its successor.');
        }else{
            $(e).parent().closest("tr").find("input").replaceWith("<span id='successor_Name' class='successor_Name'>"+successorInput+"</span>");
            $(e).hide();
            var successorPath, successorId;
            for(var i = 0 ; i < processListObj.length ; i++){
                if(processListObj[i].processname == successorInput.split("-")[0] &&
                        processListObj[i].processversion == successorInput.split("-")[1]){
                    successorPath = processListObj[i].path;
                    successorId = processListObj[i].processid;
                    break;
                }
            }

            var successorInfo = {
                name: successorInput.split("-")[0],
                path: successorPath,
                id: successorId
            };

            var successorDetails = {
                'processName': $('#view-header').text(),
                'processVersion' : $('#process-version').text(),
                'successor' : successorInfo
            };

            $.ajax({
                url: 'https://localhost:9443/publisher/assets/process/apis/update_successor',
                type: 'POST',
                data: { 'successorDetails': JSON.stringify(successorDetails) },
                success: function (response) {
                    alertify.success('Process ' + successorInput + ' successfully added to the successor list.');
                },
                error: function () {
                    alertify.error('Error');
                }
            });
        }
    }

    function readUpdatedPredecessor(e){
        var predecessorInput = $(e).parent().closest("tr").find("input").val();

        if(predecessorInput == ''){
            alertify.error('Field is empty.');
        }else if(isProcessNotAvailableInList(predecessorInput)){
            alertify.warning('Please enter correct process name that exists.');
        }else if(predecessorInput == getMainProcess()){
            alertify.warning('You cannot assign the process name as its predecessor.');
        }else{
            $(e).parent().closest("tr").find("input").replaceWith("<span id='predecessor_Name' class='predecessor_Name'>"+predecessorInput+"</span>");
            $(e).hide();
            var predecessorPath, predecessorId;
            for(var i = 0 ; i < processListObj.length ; i++){
                if(processListObj[i].processname == predecessorInput.split("-")[0] &&
                        processListObj[i].processversion == predecessorInput.split("-")[1]){
                    predecessorPath = processListObj[i].path;
                    predecessorId = processListObj[i].processid;
                    break;
                }
            }

            var predecessorInfo = {
                name: predecessorInput.split("-")[0],
                path: predecessorPath,
                id: predecessorId
            };

            var predecessorDetails = {
                'processName': $('#view-header').text(),
                'processVersion' : $('#process-version').text(),
                'predecessor' : predecessorInfo
            };

            $.ajax({
                url: 'https://localhost:9443/publisher/assets/process/apis/update_predecessor',
                type: 'POST',
                data: { 'predecessorDetails': JSON.stringify(predecessorDetails) },
                success: function (response) {
                    alertify.success('Process ' + predecessorInput + ' successfully added to the predecessor list.');
                },
                error: function () {
                    alertify.error('Error');
                }
            });
        }
    }

    function deleteSubprocess(e){
        var deleteSubInput = $(e).parent().closest("tr").find("span").text();
        if(! isProcessNotAvailableInList(deleteSubInput)){
            var deleteSubPath, deleteSubId;
            for(var i = 0 ; i < processListObj.length ; i++){
                if(processListObj[i].processname == deleteSubInput.split("-")[0] &&
                        processListObj[i].processversion == deleteSubInput.split("-")[1]){
                    deleteSubPath = processListObj[i].path;
                    deleteSubId = processListObj[i].processid;
                    break;
                }
            }

            var deleteSubInfo = {
                name: deleteSubInput.split("-")[0],
                path: deleteSubPath,
                id: deleteSubId
            };

            var deleteSubObj = {
                'processName': $('#view-header').text(),
                'processVersion' : $('#process-version').text(),
                'deleteSubprocess' : deleteSubInfo
            };

            $.ajax({
                url: 'https://localhost:9443/publisher/assets/process/apis/delete_subprocess',
                type: 'POST',
                data: { 'deleteSubprocessDetails': JSON.stringify(deleteSubObj) },
                success: function (response) {
                    alertify.success('Successfully deleted ' + deleteSubInput + ' from the subprocess list.');
                },
                error: function () {
                    alertify.error('Error');
                }
            });
        }
    }

    function deleteSuccessor(e){
        var deleteSuccessorInput = $(e).parent().closest("tr").find("span").text();
        if(! isProcessNotAvailableInList(deleteSuccessorInput)){
            var deleteSuccessorPath, deleteSuccessorId;
            for(var i = 0 ; i < processListObj.length ; i++){
                if(processListObj[i].processname == deleteSuccessorInput.split("-")[0] &&
                        processListObj[i].processversion == deleteSuccessorInput.split("-")[1]){
                    deleteSuccessorPath = processListObj[i].path;
                    deleteSuccessorId = processListObj[i].processid;
                    break;
                }
            }

            var deleteSuccessorInfo = {
                name: deleteSuccessorInput.split("-")[0],
                path: deleteSuccessorPath,
                id: deleteSuccessorId
            };

            var deleteSuccessorObj = {
                'processName': $('#view-header').text(),
                'processVersion' : $('#process-version').text(),
                'deleteSuccessor' : deleteSuccessorInfo
            };

            $.ajax({
                url: 'https://localhost:9443/publisher/assets/process/apis/delete_successor',
                type: 'POST',
                data: { 'deleteSuccessorDetails': JSON.stringify(deleteSuccessorObj) },
                success: function (response) {
                    alertify.success('Successfully deleted ' + deleteSuccessorInput + ' from the successor list.');
                },
                error: function () {
                    alertify.error('Error');
                }
            });
        }
    }

    function deletePredecessor(e){
        var deletePredecessorInput = $(e).parent().closest("tr").find("span").text();
        if(! isProcessNotAvailableInList(deletePredecessorInput)){
            var deletePredecessorPath, deletePredecessorId;
            for(var i = 0 ; i < processListObj.length ; i++){
                if(processListObj[i].processname == deletePredecessorInput.split("-")[0] &&
                        processListObj[i].processversion == deletePredecessorInput.split("-")[1]){
                    deletePredecessorPath = processListObj[i].path;
                    deletePredecessorId = processListObj[i].processid;
                    break;
                }
            }

            var deletePredecessorInfo = {
                name: deletePredecessorInput.split("-")[0],
                path: deletePredecessorPath,
                id: deletePredecessorId
            };

            var deletePredecessorObj = {
                'processName': $('#view-header').text(),
                'processVersion' : $('#process-version').text(),
                'deletePredecessor' : deletePredecessorInfo
            };

            $.ajax({
                url: 'https://localhost:9443/publisher/assets/process/apis/delete_Predecessor',
                type: 'POST',
                data: { 'deletePredecessorDetails': JSON.stringify(deletePredecessorObj) },
                success: function (response) {
                    alertify.success('Successfully deleted ' + deletePredecessorInput + ' from the predecessor list.');
                },
                error: function () {
                    alertify.error('Error');
                }
            });
        }
    }

    function updateProcessOwner(e){
        var processOwner = $(e).parent().closest("tr").find("td:eq(1)").text();
        if(processOwner == ''){
            alertify.error('Field is empty.');
        }else{
            var ownerDetails = {
                'processName': $('#view-header').text(),
                'processVersion' : $('#process-version').text(),
                'processOwner' : processOwner
            };

            $.ajax({
                url: 'https://localhost:9443/publisher/assets/process/apis/update_owner',
                type: 'POST',
                data: { 'ownerDetails': JSON.stringify(ownerDetails) },
                success: function (response) {
                    $(e).hide();
                    alertify.success('Successfully updated the Process owner name.');
                },
                error: function () {
                    alertify.error('Error');
                }
            });
        }
    }

    function isInputFieldEmpty(tableName){
        var isFieldEmpty = false;
        $('#table_' + tableName + ' tbody tr').each(function(){
            if($(this).find('td:eq(0) input').val() == ''){
                isFieldEmpty = true;
            }
        });
        return isFieldEmpty;
    }

    function addUnboundedRow(e){
        var tableName = $(e).attr('data-name');
        var table = $('#table_'+tableName);

        if(! isInputFieldEmpty(tableName)) {
            var referenceRow = $('#table_reference_' + tableName);
            var newRow = referenceRow.clone().removeAttr('id');
            $('input[type="text"]', newRow).val('');
            table.show().append(newRow);
        }else{
            alertify.error('Please fill the empty ' + tableName + ' field.');
        }
    }

</script>

<h2 id="view-header">{{assets.tables.[0].fields.name.value}}</h2>
<br/>
<div id="overviewDiv">
            <table class="table table-responsive" style="width: 8cm;border-bottom:0px !important;">
                <tbody>
                <tr>
                    <td width="40%" style="border: 0px !important;">Version:</td>
                    <td width="60%" id="process-version" style="border: 0px !important;">{{assets.tables.[0].fields.version.value}}</td>
                </tr>
                <tr>
                    <td width="40%" style="border: 0px !important;">Owner:</td>
                    <td width="40%" style="border: 0px !important;" contenteditable="true" onblur="editProcessOwner(this)">{{assets.tables.[0].fields.owner.value}}</td>
                    <td width="20%" style="border: 0px !important;"><span id="processOwnerUpdateBtn" class="glyphicon glyphicon-ok" data-toggle="tooltip" title="Click here to update the value" style="color:#0081c2;cursor: pointer;display: none;" onclick="updateProcessOwner(this)"></span></td>
                </tr>
                </tbody>
            </table>

            <div class="control-group" style="display: inline-block">
                {{#if processTextAvaliable}}
                    <div id="vtdiv"><button id="viewTextButton" class="btn btn-primary" onclick="viewText()">View/Edit Process Text</button></div>
                    <div id="atdiv"><button id="addTextButton" class="btn btn-primary" onclick="showTextEditor()" style="display: none">Describe process in text</button></div>
                {{else}}
                    <div id="vtdiv"><button id="viewTextButton" class="btn btn-primary" onclick="viewText()" style="display: none">View/Edit Process Text</button></div>
                    <div id="atdiv"><button id="addTextButton" class="btn btn-primary" onclick="showTextEditor()">Describe process in text</button></div>
                {{/if}}
            </div>

            <div class="control-group" style="display: inline-block">
                {{#if bpmnAvaliable}}
                    <button class="btn btn-primary" onclick="showBPMN()">Show BPMN</button>
                    <!--<a href="../../bpmn/details/{{assets.tables.[1].fields.bpmnid.value}}">Show BPMN</a>-->
                {{else}}
                    <button class="btn btn-primary" onclick="showBPMNUploader()">Associate a BPMN model</button>
                {{/if}}
            </div>
            <br /><br />

    <form class="form-horizontal">
        <div class="control-group">

            <h2 class="field-title">
                <a class="collapsing-h2" aria-expanded="true" href="#subprocess" data-toggle="collapse" rel="tooltip" title="List of subprocesses for a given process">
                    <i class="cu-btn-exp-col btn-collapsed">Subprocess</i>
                </a>
            </h2>

            <div id="subprocess" class="responsive-form-container collapse in" aria-expanded="true" style="">
                <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12" style="padding:0">
                    &nbsp;
                </div>
                <div style="border:0px solid #ff0000; padding:0" class="col-lg-10 col-md-10 col-sm-12 col-xs-12">
                    <div class="add-unbounded-row"><a data-name="subprocess" onclick="addUnboundedRow(this)"><i class="fa fa-plus-circle"></i> Add Subprocess</a></div>
                    <table class="tablex cu-data-table js-unbounded-table" id="table_subprocess">
                        <thead>

                        <tr><th></th>
                        </tr></thead>
                        <tbody>
                        {{#each involveProcessList.subprocesses}}
                            <tr>
                                <td valign="top" style="width: 90%;"><span id="subprocess_Name" class="subprocess_Name">{{this.name}}-{{this.version}}</span></td>
                                <td style="width: 5%;"></td>
                                <td style="width: 5%;"><a class="js-remove-row" onclick="deleteSubprocess(this)"><i class="fa fa-trash"></i></a> </td>
                            </tr>
                        {{/each}}
                        </tbody>
                    </table>
                </div>
            </div>

            <h2 class="field-title">
                <a class="collapsing-h2" aria-expanded="true" href="#successor" data-toggle="collapse" rel="tooltip" title="List of successor processes for a given process">
                    <i class="cu-btn-exp-col btn-collapsed">Successor</i>
                </a>
            </h2>
            <div id="successor" class="responsive-form-container collapse in" aria-expanded="true" style="">
                <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12" style="padding:0">
                    &nbsp;
                </div>
                <div style="border:0px solid #ff0000; padding:0" class="col-lg-10 col-md-10 col-sm-12 col-xs-12">
                    <div class="add-unbounded-row"><a data-name="successor" onclick="addUnboundedRow(this)"><i class="fa fa-plus-circle"></i> Add Successor</a></div>
                    <table class="tablex cu-data-table js-unbounded-table" id="table_successor">
                        <thead>

                        <tr><th></th>
                        </tr></thead>
                        <tbody>
                        {{#each involveProcessList.successors}}
                            <tr>
                                <td valign="top" style="width: 90%;"><span id="successor_Name" class="successor_Name">{{this.name}}-{{this.version}}</span></td>
                                <td style="width: 5%;"></td>
                                <td style="width: 5%;"><a class="js-remove-row" onclick="deleteSuccessor(this)"><i class="fa fa-trash"></i></a> </td>
                            </tr>
                        {{/each}}
                        </tbody>
                    </table>
                </div>
            </div>


            <h2 class="field-title">
                <a class="collapsing-h2" aria-expanded="true" href="#predecessor" data-toggle="collapse" rel="tooltip" title="List of predecessor processes for a given process">
                    <i class="cu-btn-exp-col btn-collapsed">Predecessor</i>
                </a>
            </h2>

            <div id="predecessor" class="responsive-form-container collapse in" aria-expanded="true" style="">
                <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12" style="padding:0">
                    &nbsp;
                </div>
                <div style="border:0px solid #ff0000; padding:0" class="col-lg-10 col-md-10 col-sm-12 col-xs-12">
                    <div class="add-unbounded-row"><a data-name="predecessor" onclick="addUnboundedRow(this)"><i class="fa fa-plus-circle"></i> Add Predecessor</a></div>
                    <table class="tablex cu-data-table js-unbounded-table" id="table_predecessor">
                        <thead>

                        <tr><th></th>
                        </tr></thead>
                        <tbody>
                        {{#each involveProcessList.predecessors}}
                            <tr>
                                <td valign="top" style="width: 90%;"><span id="predecessor_Name" class="predecessor_Name">{{this.name}}-{{this.version}}</span></td>
                                <td style="width: 5%;"></td>
                                <td style="width: 5%;"><a class="js-remove-row" onclick="deletePredecessor(this)"><i class="fa fa-trash"></i></a> </td>
                            </tr>
                        {{/each}}
                        </tbody>
                    </table>
                </div>
            </div>

        </div>
{'fraction_non_alphanumeric': 0.15179941682013506, 'fraction_numerical': 0.007328115408225906, 'mean_word_length': 1.7167500521159058, 'pattern_counts': {'":': 0, '<': 393, '<?xml version=': 0, '>': 377, 'https://': 22, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3113630', 'n_tokens_mistral': 14176, 'n_tokens_neox': 13306, 'n_words': 2282}