var MagicEditor = { init : function(){ this.config = {}; var skin = this.getValue('skin'); if(skin){ $('body').addClass('skin-' + skin); } this.addedGroups = {}; this.apiId = null; this.apiList = []; this.debugSessionId = null; this.defaultRequestValue = '{\r\n\t"request" : {\r\n\t\t"message" : "Hello MagicAPI!"\r\n\t},\r\n\t"path" : {\r\n\t\t"id" : "123456"\r\n\t},\r\n\t"header" : {\r\n\t\t"token" : "tokenValue"\r\n\t}\r\n}'; this.initMTA(); this.initShortKey(); this.initSkin(); this.initLeftToobarContainer(); this.initBottomContainer(); this.initSelect(); this.initContextMenu(); this.initScriptEditor(); this.resetEditor(); this.checkUpdate(); this.backupInterval(); this.login(); var _this = this; $.getJSON('config.json',function(data){ _this.config = data; Parser.importPackages = ['java.util.','java.lang.'].concat((_this.config.autoImportPackage||'').replace(/\\s/g,'').replace(/\*/g,'').split(',')); }) }, initSkin : function(){ var skinSelector = $('.skin-selector'); $('.button-skin').on('click',function(){ skinSelector.toggle(); return false; }); var $body = $('body'); $body.on('click',function(){ skinSelector.hide(); }) var _this = this; skinSelector.on('click','li',function(){ skinSelector.hide(); $(this).siblings().each(function(){ $body.removeClass('skin-' + $(this).text()) }) _this.setSkin($(this).text()); }) }, login : function(){ $('.loading-wrapper').remove(); var _this = this; this.ajax({ url : 'login', async : false, success : function(successed){ if(!successed){ MagicEditor.createDialog({ title : '登录', shade : true, content : '
', replace : false, allowClose : false, autoClose : false, buttons : [{ name : '登录', click : function($dom){ var username = $dom.find('input[name=username]').val(); var password = $dom.find('input[name=password]').val(); var successed = false; _this.ajax({ url : 'login', data : { username : username, password : password }, async : false, success : function(succ){ successed = succ; } }) if(!successed){ _this.alert('登录','登录失败,用户名或密码不正确'); return false; } _this.loadAPI(); } }] }) }else{ _this.loadAPI(); } } }) }, resetEditor : function(){ $('input[name=group]').val('未分组'); $('input[name=method]').val('GET'); $('input[name=name]').val(''); $('input[name=path]').val(''); $('input[name=prefix]').val(''); this.outputJson = null; this.apiId = null; this.scriptEditor&&this.scriptEditor.setValue('return message;'); this.requestEditor && this.requestEditor.setValue(this.defaultRequestValue); this.resultEditor&&this.resultEditor.setValue(''); this.optionsEditor && this.optionsEditor.setValue('{\r\n}'); }, addBreakPoint : function(line){ var model = this.scriptEditor.getModel(); model.deltaDecorations([],[{ range : new monaco.Range(line, 1, line, 1), options: { isWholeLine: true, linesDecorationsClassName: 'breakpoints', className : 'breakpoint-line', } }]) }, removeBreakPoint : function(line){ var model = this.scriptEditor.getModel(); var decorations = []; if (line !== undefined) { decorations = model.getLineDecorations(line); } else { decorations = model.getAllDecorations(); } var ids = []; for (var i=0,len =decorations.length;i 0){ var $groupUL = $('input[name=group]').next(); for(var i=0,len = apiList.length;i').append(info.groupName)) } } if(info.show!==false){ groups[info.groupName].children.push({ id : info.id, groupName : info.groupName, groupPrefix : info.groupPrefix, name : info.name, title : '" + info.path, path : info.path }); } } } for(var key in this.addedGroups){ if(!groups[key]){ groups[key] = this.addedGroups[key]; } } var $dom = $('.api-list-container').html(''); for(var key in groups){ var group = groups[key]; var $item = $('
').addClass('group-item') .addClass('opened') .append($('
').addClass('group-header') .append('') .append($('