123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071 |
- 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)
- {
- 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)
- {
- notice('操作已成功!您的操作已修改当前选项!');
- })
- }
- function notice(msg)
- {
- var notice = new PNotify({
- title: '提示信息',
- text: msg,
- buttons: {
- closer: false,
- sticker: false
- }
- });
- notice.get().click(function() {
- notice.remove();
- });
- }
- //模板选择
- 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 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
- {
- notice(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)
- {
- notice('修改成功');
- /*
- 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('确定进行此项操作吗?'))
- {
- if(href.indexOf('&') == -1)
- {
- href += '?callback=?';
- }
- else
- {
- href += '&callback=?';
- }
- $.getJSON(href, {}, 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);
- }
- };
|