1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057 |
- var editors = [];
- $(document).ready(function()
- {
- init();
- });
- function init()
- {
- edit();
- del();
- checkbox();
- image();
- change();
- autocomplete();
- template();
- submit();
- loadShow();
- initEditor();
- //更新页面一些功能,上边的一些功能等找时间再优化吧
- Maze_update.init();
-
- }
- function initEditor()
- {
- if($('.editor').length)
- {
- $('.editor').each(function()
- {
- var parent = $(this).parent().parent();
- //alert(parent.attr('id'));
- if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
- {
- return;
- }
- loadEditor($(this));
- })
- }
- }
- function loadEditor(e)
- {
- if(!e.length)
- {
- return;
- }
- var id = e.attr('id');
- var key = e.attr('key');
- if(typeof(UM) == "undefined")
- {
- var u = UE;
- }
- else
- {
- var u = UM;
- }
-
- if(typeof(editors[id]) == "undefined")
- {
- editors[id] = u.getEditor(id,
- {
- imageUrl : config.upload + '.ueditor?key=' + key
- });
- }
- }
- //更新页面的提交按钮
- function submit()
- {
- if($(".save-data").length)
- {
- $(".save-data").bind('click', function()
- {
- $(".form1").submit();
- //$(this).unbind('click');
- })
- }
- }
- //头部菜单
- function topMenu(e)
- {
- var p = e.parent().parent().parent().find('span');
- p.html(e.html());
- //更新当前的精细权限
- var url = config.host + 'top.update_action?json=1';
- var id = e.attr('data-id');
- $.post(url, {id:id}, function(t)
- {
- if(location.href.indexOf('where_id') != -1)
- {
- var href = location.href.split('where_id');
- location.href = href[0] + 'where_id=' + t;
- }
- else
- {
- location.reload();
- }
- })
- }
- //更新页面的批量载入选择
- function loadShow()
- {
- if($(".show_input").length)
- {
- $(".show_input input").each(function()
- {
- if($(this).attr('checked'))
- {
- $(this).click().attr('checked',true);
- }
- })
- }
- }
- function inputShow(e,n)
- {
- var item = e.parent().find('input');
-
- $(".show_" + n).hide();
-
- var array = ['input', 'textarea'];
- for(var a in array)
- {
- $(".show_" + n).find(array[a]).removeClass('validate[required]');
- }
-
- item.each(function()
- {
- if($(this).get(0).checked == true)
- {
- inputShowOne($(this),n);
- }
- });
- }
- function inputShowOne(e,n)
- {
- var value = e.val();
- //$(".show_" + n).hide();
- //$(".show_" + n + '_' + value).attr('style','color:red').show();
- $(".show_" + n + '_' + value).show();
- var array = ['input', 'textarea'];
- for(var a in array)
- {
- if($(".show_" + n + '_' + value).length && $(".show_" + n + '_' + value).attr('class').indexOf('show_no') == -1)
- {
- $(".show_" + n + '_' + value).find(array[a]).each(function()
- {
- var parent = $(this).parent();
- if($(this).attr('class') != 'editor' && parent.find('label').length && parent.find('label').html().indexOf('选填') == -1)
- {
- $(this).addClass('validate[required]');
- }
- })
- }
- }
- }
- //批量更新
- function list_mul(e)
- {
- var type = parseInt($("#mul_type").val());
- if(type != 1 && type != 2)
- {
- alert('您还没有选择数据更新方式');
- return;
- }
- if(confirm('确定进行此项操作吗?'))
- {
- //e.html('更新中').unbind('click');
- $('#method').val('mul');
- $('#function').val('msg');
- $('#form1').attr('target', 'f1').submit();
- }
- }
- //搜索
- function list_search(e)
- {
- $('#method').val('search');
- $('#function').val('');
- $('#form1').attr('target', '').submit();
- }
- //更新数据
- function update(e, id, key, table)
- {
- if(confirm('您这项操作将更改当前的选项,请确认是否继续进行?'))
- {
- var col = e.attr('name');
- var value = e.val();
- var url = config.host + 'database.update_action?json=1';
- $.post(url, {where_id:id,col:col,value:value,key:key,table:table}, function(t)
- {
- alert('操作成功');
- })
- }
- }
- //模板选择
- function template()
- {
- if(config.template)
- {
- $('body').attr('class', 'theme-' + config.template);
- }
- if($(".selector").length)
- {
- $(".selector").each(function()
- {
- if($(this).data('check') == 'checked')
- {
- selector($(this));
- }
- })
- }
- }
- //选择器
- function selector(e)
- {
- var value = e.data('value');
- var name = e.data('name');
- $('#'+name+'_value').val(value);
- $('.'+name+'_selector').children().css({'border':'1px solid #ccc'});
- e.children().css({'border':'1px solid black'});
- if(name == 'update_template')
- {
- $('body').attr('class', 'theme-' + value);
- }
- }
- function autocomplete()
- {
- if($("input[complete]").length)
- {
- $("input[complete]").each(function()
- {
- var cache = {};
- var self = $(this);
- self.autocomplete(
- {
- minLength: 2,
- source: function( request, response )
- {
- var term = request.term;
- if ( term in cache ) {
- response( cache[ term ] );
- return;
- }
-
- $.getJSON(self.attr('complete') + '&callback=?', request, function( data, status, xhr ) {
- console.info(data);
- cache[ term ] = data;
- response( data );
- });
- }
- });
- })
- }
- }
- //后台头部提示
- function top_msg(value)
- {
-
- }
- //后台通用的提示
- function msg(value)
- {
- var url = '';
- if(value.msg != 'reload' && value.status == 2)
- {
- submit();
- //showAlert(value.msg);
- alert(value.msg);
- location.reload();
- return;
- }
- else
- {
- if(value.msg.indexOf('http://') != -1)
- {
- url = value.msg;
- }
- else if($("#url").length)
- {
- url = $("#url").val();
- }
- else
- {
- //showAlert(value.msg);
- return;
- }
- if(url)
- {
- location.href = url;
- }
- else
- {
- location.reload();
- }
- }
-
- return;
- }
- /**
- * 处理多选问题,处理全选按钮
- */
- function checkbox()
- {
- var name = 'checkbox-checkall';
- var checkbox = $("." + name);
- if(checkbox.length)
- {
- checkbox.click(function()
- {
- var self = $(this);
- $("." + name + "-" + self.val()).each(function()
- {
- $(this).get(0).checked = self.get(0).checked;
-
- var next = $(this).next();
-
- if($(this).get(0).checked == true)
- {
- if(next.length)
- {
- next.attr('disabled', false);
- }
- if($("#mul_type").length)
- {
- $("#mul_type").val(1);
- }
- }
- else
- {
- if(next.length)
- {
- next.attr('disabled', true);
- }
-
- if($("#mul_type").length)
- {
- $("#mul_type").val(0);
- }
- }
- })
- });
- checkbox.each(function()
- {
- var self = $(this);
- $("." + name + "-" + self.val()).each(function()
- {
- $(this).click(function()
- {
- var next = $(this).next();
-
- if($(this).get(0).checked == true)
- {
- self.get(0).checked = true;
- if(self.attr('type') == 'radio')
- {
- //如果父选项是radio类型,做下限制
- //alert(1);
- }
- if($("#mul_type").length)
- {
- $("#mul_type").val(1);
- }
-
- if(next.length)
- {
- next.attr('disabled', false);
- }
- }
- else
- {
- //子选项取消时,处理一下父级选项
- var num = 0;
- $("." + name + "-" + self.val()).each(function()
- {
- if($(this).get(0).checked == true)
- {
- num = 1;
- }
- });
-
- if(num == 0)
- {
- self.get(0).checked = false;
-
- if($("#mul_type").length)
- {
- $("#mul_type").val(0);
- }
- }
-
- if(next.length)
- {
- next.attr('disabled', true);
- }
- }
- })
- if($(this).get(0).checked == true)
- {
- self.get(0).checked = true;
- }
- });
- })
- }
- }
- /**
- * 处理双击编辑
- */
- function edit()
- {
- if($(".edit").length)
- {
- $(".edit").each(function()
- {
- $(this).bind('dblclick', function()
- {
- var col = $(this).attr('data-col');
- var key = $(this).attr('data-key');
- var table = $(this).attr('data-table');
- var url = $(this).attr('data-url');
- var id = $(this).attr('data-id');
- var html = $(this).attr('data-content');
- var type = $(this).attr('data-type');
- if($(this).find(".edit-content").length)
- {
- html = $(this).find(".edit-content").html();
- html = html.replace('<!--', '<');
- html = html.replace('-->', '>');
- }
-
- if(html.indexOf('input') == -1)
- {
- if(type && type == 'textarea')
- {
- $(this).html('<textarea type="text" name="edit" id="edit" rows="20" cols="80">'+html+'</textarea>');
- }
- else
- {
- $(this).html('<input type="text" name="edit" id="edit" value="'+html+'">');
- }
- var self = $(this);
- self.find("#edit").blur(function()
- {
- var value = self.find("#edit").val();
- if(!value)
- {
- alert('不能为空');
- return;
- }
-
- if($(this).find(".edit-content").length)
- {
- $(this).find(".edit-content").html(value);
- }
- else
- {
- self.attr('data-content', value);
- }
-
- self.html(value);
-
- $.post(url, {key:key,table:table,value:value,where_id:id,col:col}, function(t)
- {
- top_msg('修改成功');
- /*
- if(type && type == 'textarea')
- {
- self.html(t);
- }
- */
- })
- })
- }
- });
- })
- }
- }
- function del()
- {
- if($(".oper_6").length)
- {
- $(".oper_6").each(function()
- {
- var href = $(this).attr('href');
- $(this).attr('href', '#');
- $(this).unbind('click');
-
- $(this).bind('click', function()
- {
- del_act(href);
- });
- })
- }
- }
- /**
- * 处理删除
- */
- function del_act(href)
- {
- if(confirm('确定进行此项操作吗?'))
- {
- $.getJSON(href, {}, function(t)
- {
- msg(t);
- })
- }
- }
- /**
- * 处理特殊加载的按钮
- */
- function load(href)
- {
- if(confirm('确定进行此项操作吗?'))
- {
- $.getJSON(href + '&callback=?', {}, function(t)
- {
- //msg(t);
- location.reload();
- })
- }
- /*
- showAlert('确定进行此项操作吗?', function()
- {
- $("#maze_modal_no").click();
- $.getJSON(href + '&json=1', {}, function(t)
- {
- msg(t);
- })
- });
- */
- }
- /**
- * 处理特殊加载的按钮
- */
- function jump(href)
- {
- location.href = href;
- }
- /**
- * 处理change
- */
- function change()
- {
- if($(".change").length)
- {
- $(".change").each(function()
- {
- var key = $(this).attr('data-child');
- /*
- $('.' + key).each(function()
- {
- if($(this).find('select option:selected').val())
- {
- $(this).show();
- $('#set_cate_id_child').get(0).value = $(this).attr('parent');
- }
- });
- */
- $(this).change(function()
- {
- $('.' + key).hide();
- var v = $('.' + key + '_' + $(this).val());
- var s = v.find('select');
- s.change(function()
- {
- $('.' + key + '_value').val($(this).val());
- })
- if(v.length)
- {
- $('.' + key + '_value').val(s.val());
- v.show();
- }
- else
- {
- $('.' + key + '_value').val(-1);
- }
- });
-
- if($(this).val() > 0)
- {
- $(this).change();
- }
- });
- }
- }
- /**
- * 处理图库系统
- */
- function image()
- {
- if($(".image_upload").length)
- {
- $(".image_upload").each(function(i)
- {
- var parent = $(this).parent().parent();
- //alert(parent.attr('id'));
- if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
- {
- return;
- }
- loadUpload(i,$(this),$(this).attr('key'),config.upload + '.start', config.lib + 'upload/');//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
- })
- }
- }
- /**
- * 修改密码
- */
- function pass(e)
- {
- var html = '<style>.password_edit div{margin:10px;}.password_edit input{width:200px;}</style><div class="password_edit">';
- html += '<div><span>旧密码:</span><input type="password" class="form-control" id="edit_old_password" /></div>';
- html += '<div><span>新密码:</span><input type="password" class="form-control" id="edit_new_password" /></div>';
- html += '</div>';
- $('#maze_modal_body').html(html);
-
- $('#maze_modal_title').html('修改密码');
-
- $("#maze_modal_yes").unbind('click').bind('click', function()
- {
- var old_password = $("#edit_old_password").val();
- var new_password = $("#edit_new_password").val();
-
- if(!old_password || !new_password)
- {
- alert('请输入密码');
- return;
- }
- if(old_password == new_password)
- {
- alert('旧密码和新密码相同');
- return;
- }
- $.post(config.host + 'auth.password', {old:old_password,new:new_password}, function(t)
- {
- alert(t);
- $("#maze_modal_no").click();
- })
- })
- }
- var MSG = [];
- /**
- * 打开弹窗
- */
- function showMsg(title, e, id, func)
- {
- var html = $(id).html();
-
- if($(id).html())
- {
- var html = $(id).html();
- MSG[id] = html;
- $(id).html('');
- }
- else
- {
- var html = MSG[id];
- }
-
- $('#maze_modal_body').html(html);
-
- $('#maze_modal_title').html(title);
-
- if(func)
- {
- $("#maze_modal_yes").unbind('click').bind('click', func);
- }
- }
- function showAlert(msg, func)
- {
- //$("#maze_modal_no").click();
- $("#maze_modal").modal();
- $('#maze_modal_body').html(msg);
-
- $('#maze_modal_title').html('提醒您');
-
- if(func)
- {
- $("#maze_modal_yes").unbind('click').bind('click', func);
- }
- else
- {
- $("#maze_modal_yes").unbind('click').bind('click', function(){$("#maze_modal_no").click()});
- }
- }
- /*
- var test =
- {
- refreshPage: false,
- addAjaxFlag: true,
- //添加收藏
- add: function(cfg)
- {
- }
- }
- */
- function showToggle(e)
- {
- var id = e.attr('toggle');
- var child = e.attr('toggle_child');
- var parent = e.parent();
- parent.parent().find('li').removeClass('active');
- parent.addClass('active');
-
- $(child).fadeOut(100);
- $(id).fadeIn(500);
- loadEditor($(id).find('.editor'));
- }
- //处理更新页面的一些功能,写到一起吧
- var Maze_update =
- {
- addIndex : 2,
- index : [],
- auto : false,
- save_key : '',
- init : function()
- {
- var self = this;
- // 增加整个更新的表单
- if($(".maze_update_add").length)
- {
- $('.maze_update_add').unbind('click').bind('click', function()
- {
- self.add($(this));
- })
- }
-
- /* 以后再增加 同时更新另外一个表
- if($(".form-add-content").length)
- {
- var url = config.host + 'auth.password';
- var url = 'http://localhost/mazephp/manage/?database.update?key=weixin&table=message&menu=weixin&menu_id=39&ajax=1';
- $.get(url, function(t)
- {
- $(".form-add-content").html(t);
- init();
- })
- }
- */
- //增加某一部分表单
- if($(".maze_form_add").length)
- {
- $('.maze_form_add').each(function()
- {
- var key = $.attr('toggle_key');
- if(typeof(self.index[key]) == "undefined")
- {
- self.index[key] = 0;
- }
- $(this).unbind('click').bind('click', function()
- {
- self.append($(this));
- })
- })
- self.del();
- }
-
- // 开启自动保存
- if($("#struct").length)
- {
- var save = $("#struct").attr('save');
-
- if(save == 'yes')
- {
- //检测
- self.save_key = location.href + 'test';
- self.check();
- }
- }
- },
-
- save : function()
- {
- //var data = $("#data-1").html();
- var data = [];
- $(".update_value").each(function(i)
- {
- if($(this).attr("update_type") == 'checked')
- {
- data[i] = $(this).get(0).checked;
- }
- else if($(this).attr("update_type") == 'html')
- {
- data[i] = $(this).html();
- }
- else if($(this).attr("update_type") == 'src')
- {
- data[i] = $(this).attr('src');
- }
- else
- {
- data[i] = $(this).val();
- }
- });
-
- store.set(this.save_key, data.join('|||'));
- //console.info(data);
- },
-
- recover : function()
- {
- if(confirm('确定恢复上次保存的数据吗?'))
- {
- var data = store.get(this.save_key).split('|||');
- if(data)
- {
- var value = $(".update_value");
- for(var k in data)
- {
- var e = value.eq(k);
- if(e.attr('update_type') == 'checked')
- {
- if(data[k] == 'true')
- {
- e.get(0).checked = true;
- }
- else
- {
- e.get(0).checked = false;
- }
- }
- else if(e.attr('update_type') == 'html')
- {
- e.html(data[k]);
- }
- else if(e.attr('update_type') == 'src')
- {
- e.attr('src', data[k]);
- }
- else
- {
- if(e.attr('id'))
- {
- var id = e.attr('id');
- if(typeof(editors[id]) != "undefined")
- {
- editors[id].setContent(data[k]);
- }
- }
-
- e.val(data[k]);
- }
- }
-
- store.set(this.save_key, '');
-
- this.check();
- }
- }
- },
-
- check : function()
- {
- var data = store.get(this.save_key);
- var self = this;
- if(data)
- {
- $(".maze_save").unbind('click').bind('click', function()
- {
- self.recover();
- }).show();
- }
- else
- {
- $(".maze_save").hide();
- self.auto = setInterval(function(){self.save()}, 3000);
- }
- },
-
- del : function()
- {
- var self = this;
- if($(".maze_form_delete").length)
- {
- $('.maze_form_delete').each(function()
- {
- $(this).unbind('click').bind('click', function()
- {
- var parent = $(this).parent();
-
- var id = parent.attr('id');
- var index = parseInt($('#tab-' + id).attr('toggle_id'));
- var key = $('#tab-' + id).attr('toggle_key');
- if(index <= 1 && self.index[key] <= index)
- {
-
- }
- else if(index <= 1 && self.index[key] > index)
- {
- index = index+1;
- $("#tab-"+key+"-child-" + index).click();
- }
- else
- {
- index = index-1;
- $("#tab-"+key+"-child-" + index).click();
- };
-
- $('#tab-' + id).parent().remove();
- parent.remove();
- })
- })
- }
- },
- append : function(e)
- {
- var self = this;
- var key = e.attr('toggle_key');
- var child = '.maze_'+key+'_child';
-
- if(typeof(self.index[key]) == "undefined")
- {
- self.index[key] = 0;
- }
-
- if(self.index[key] <= 0)
- {
- self.index[key] = $(child).length;
- }
-
- if(self.index[key] > 10)
- {
- alert('最多只能增加10条');
-
- return;
- }
-
- var p = e.parent();
-
- var id = key + '-child-' + self.index[key];
-
- var name = '第' + (self.index[key]) + '条';
-
- p.before('<li><a href="javascript:;" id="tab-'+id+'" toggle_key="'+key+'" toggle_id="'+self.index[key]+'" toggle_child="'+child+'" toggle="#'+id+'" onclick="showToggle($(this))">'+name+'</a></li>');
-
-
- var e = e.parent().parent();
-
- var n = e.next();
- var p = e.parent();
-
- var content = n.html();
-
- content = content.replaceAll('_c_', '_c_' + self.index[key] + '_i_');
-
- content = '<div id="'+id+'" style="display:none;" class="'+n.attr('class')+' maze_form_add_child">' + content + '</div>';
-
- p.append(content);
-
- self.del();
- //$("html,body").animate({scrollTop:$('.maze_form_add_child').eq(this.appendIndex).offset().top},500);
-
- self.index[key]++;
- image();
-
- loadShow();
- autocomplete();
- change();
- },
- add : function(e)
- {
- var self = this;
-
- var p = e.parent();
-
- var id = 'data-' + this.addIndex;
-
- var name = '新增数据-' + (this.addIndex-1);
-
- p.before('<li><a href="#'+id+'" data-toggle="tab">'+name+'</a></li>');
-
- var content = $("#myTabContent").find('.tab-pane').eq(0).html();
-
- content = content.replaceAll('update_', 'update_' + this.addIndex + '__');
-
- content = '<div class="tab-pane fade" id="'+id+'">' + content + '</div>';
-
- $("#myTabContent").append(content);
-
- $('#update_' + this.addIndex + '__where_id').val('-1');
- this.addIndex++;
- }
- }
- String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) {
- if (!RegExp.prototype.isPrototypeOf(reallyDo)) {
- return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi": "g")), replaceWith);
- } else {
- return this.replace(reallyDo, replaceWith);
- }
- }
- Array.prototype.remove = function(val) {
- var index = -1;
- for(var i = 0; i < this.length; i++)
- {
- if(this[i] == val)
- {
- index = i;
- }
- }
- if (index > -1) {
- this.splice(index, 1);
- }
- };
|