diff --git a/module/api/css/index.css b/module/api/css/index.css index d964921401..9c95885d1b 100644 --- a/module/api/css/index.css +++ b/module/api/css/index.css @@ -10,6 +10,7 @@ #mainContent > .main-col {flex: auto; height: calc(100vh - 120px); overflow: auto;} /* tree */ +.tree-icon {position: absolute; right: 0;} /* sideBar */ diff --git a/module/api/js/index.js b/module/api/js/index.js index 13379d9aac..2cd4670d30 100644 --- a/module/api/js/index.js +++ b/module/api/js/index.js @@ -1,5 +1,22 @@ $(document).ready(function() { + /** + * Render Dropdown dom. + * + * @access public + * @return string + */ + function renderDropdown(option) + { + var libClass = '.libDorpdown'; + if(option.type != 'dropDownLibrary') libClass = '.moduleDorpdown'; + if($(libClass).find('li').length == 0) return ''; + var dropdown = ''; + return dropdown; + } + /* Update doc content silently on switch doc version, story #40503 */ $(document).on('click', '.api-version-menu a, #mainActions .container a', function(event) { @@ -16,6 +33,17 @@ $(document).ready(function() }); }); + var moduleData = { + "name" : "", + "createType" : "", + "libID" : "", + "parentID" : "", + "objectID" : "", + "moduleType" : "", + "order" : "", + "isUpdate" : "" + }; + $(document).on('click', '.sidebar-toggle > .icon', function() { var $icon = $(this); @@ -91,6 +119,163 @@ $(document).ready(function() } var linkParams = 'libID=' + libID + '&moduleID=' + moduleID; location.href = createLink('api', 'index', linkParams); + }).on('click', '.icon-drop', function(e) + { + $('.dropdown-in-tree').css('display', 'none'); + var isCatalogue = $(this).attr('data-isCatalogue') === 'false' ? false : true; + var dropDownID = isCatalogue ? 'dropDownCatalogue' : 'dropDownLibrary'; + var libID = 0; + var moduleID = 0; + var parentID = 0; + var $module = $(this).closest('a'); + var hasChildren = $module.data('has-children'); + var moduleType = ''; + if($module.hasClass('lib')) + { + libID = $module.data('id'); + moduleType = $module.data('type'); + parentID = libID; + } + else + { + moduleID = $module.data('id'); + libID = $module.closest('.lib').data('id'); + moduleType = $module.closest('.lib').data('type'); + parentID = $module.closest('ul').closest('.lib').data('id'); + } + + moduleData = { + "libID" : libID, + "parentID" : parentID, + "objectID" : moduleID, + "moduleType": moduleType == 'lib' ? 'doc' : moduleType, + }; + + var option = { + left : e.pageX, + top : e.pageY, + type : dropDownID, + libID : libID, + moduleID : moduleID, + hasChildren : hasChildren + }; + + var dropDown = renderDropdown(option); + $(".m-api-index").append(dropDown); + e.stopPropagation(); + }).on('blur', 'input.input-tree', function() + { + var $input = $(this); + var value = $input.val(); + if(!value) + { + $input.closest('[data-id=insert]').remove(); + return; + } + + moduleData.name = value; + $.post(createLink('tree', 'ajaxCreateModule'), moduleData, function(result) + { + result = JSON.parse(result); + if(result.result == 'fail') + { + bootbox.alert( + result.message[0], + function() + { + setTimeout(function() + { + $('.file-tree .input-tree').focus() + }, 10) + } + ); + return false; + } + var module = result.module; + var resultDom = $('[data-id=aTreeModal]').html().replace(/%name%/g, module.name).replace(/%id%/g, module.id).replace('insert', module.id); + $input.closest('ul').find('.has-input').css('padding-left', '15px'); + $input.after(resultDom); + $input.remove(); + if(moduleData.isUpdate) + { + $.getJSON(createLink('api', 'index', 'json'), function(data){ + var treeData = JSON.parse(data.data); + $('#fileTree').data('zui.tree').reload(treeData.libTree); + $('li.has-list > ul').addClass("menu-active-primary menu-hover-primary"); + }); + } + }); + }); + + $('body').on('click', '.dropdown-in-tree li', function(e) + { + var item = $(this).data(); + if($(this).hasClass('edit-module')) + { + new $.zui.ModalTrigger({ + keyboard : true, + type : 'ajax', + url : $(this).find('a').data('href') + }).show(); + } + if(item.type !== 'add') return; + + var $item = $(this); + moduleData.parentID = 0; + moduleData.isUpdate = false; + moduleData.createType = 'child'; + switch(item.method) + { + case 'addCataLib' : + if(item.hasChildren) + { + var $input = $('[data-id=liTreeModal]').html(); + var $rootDom = $('[data-id=' + item.libid + ']a + ul'); + $rootDom.append($input); + } + else + { + var $input = $('[data-id=ulTreeModal]').html(); + var $rootDom = $('[data-id=' + item.libid + ']a'); + var $li = $rootDom.parent(); + moduleData.isUpdate = true; + $rootDom.after($input); + $li.addClass('open in has-list'); + } + $('#fileTree').data('zui.tree').expand($('li[data-id="' + item.libid + '"]')); + $rootDom.parent().find('input').focus(); + break; + case 'addCataBro' : + moduleData.createType = 'same'; + var $input = $('[data-id=liTreeModal]').html(); + var $rootDom = $('#fileTree li[data-id=' + item.id + ']'); + $rootDom.after($input); + $rootDom.closest('ul').find('.has-input').css('padding-left', '0'); + $('#fileTree').find('input').focus(); + break; + case 'addCataChild' : + moduleData.parentID = item.id; + if(item.hasChildren) + { + var $input = $('[data-id=liTreeModal]').html(); + var $rootDom = $('#fileTree [data-id=' + item.id + ']a + ul '); + } + else + { + var $input = $('[data-id=ulTreeModal]').html(); + var $rootDom = $('#fileTree [data-id=' + item.id + ']li'); + moduleData.isUpdate = true; + $rootDom.addClass('open in has-list'); + } + + $('#fileTree').data('zui.tree').expand($('li[data-id="' + item.id + '"]')); + $rootDom.append($input); + $rootDom.find('input').focus(); + break; + } + }).on('click', function() + { + $('.dropdown-in-tree').remove(); }); }); diff --git a/module/doc/js/tablecontents.js b/module/doc/js/tablecontents.js index e56f92a0b7..342038920b 100644 --- a/module/doc/js/tablecontents.js +++ b/module/doc/js/tablecontents.js @@ -145,9 +145,53 @@ $(function() var dropDown = renderDropdown(option); $(".m-doc-tablecontents").append(dropDown); e.stopPropagation(); + }).on('blur', '.file-tree input.input-tree', function() + { + var $input = $(this); + var value = $input.val(); + if(!value) + { + $input.closest('[data-id=insert]').remove(); + return; + } + + moduleData.name = value; + $.post(createLink('tree', 'ajaxCreateModule'), moduleData, function(result) + { + result = JSON.parse(result); + if(result.result == 'fail') + { + bootbox.alert( + result.message[0], + function() + { + setTimeout(function() + { + $('.file-tree .input-tree').focus() + }, 10) + } + ); + return false; + } + var module = result.module; + var resultDom = $('[data-id=aTreeModal]').html().replace(/%name%/g, module.name).replace(/%id%/g, module.id).replace('insert', module.id); + $input.closest('ul').find('.has-input').css('padding-left', '15px'); + $input.after(resultDom); + $input.remove(); + if(moduleData.isUpdate) + { + $.getJSON(createLink('doc', 'tableContents', 'type=' + objectType + '&objectID=' + objectID , 'json'), function(data){ + var treeData = JSON.parse(data.data); + $('#fileTree').data('zui.tree').reload(treeData.libTree); + $('li.has-list > ul').addClass("menu-active-primary menu-hover-primary"); + }); + } + }); }); - $('body').on('click', function(e) +; + + $('body').on('click', function() { $('.dropdown-in-tree').remove(); }).on('click', '.sidebar-toggle', function()