123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686 |
- //这里的代码是最早写的,很乱,以后整合优化
- var editors = [];
- $(document).ready(function()
- {
- //init();
- });
- function init()
- {
- edit();
- del();
- checkbox();
- image();
- change();
- autocomplete();
- template();
- submit();
- loadShow();
- initEditor();
- initPic();
- initDate();
- //更新页面一些功能,上边的一些功能等找时间再优化吧
- dever_update.init();
- hljs.initHighlightingOnLoad();
- table();
- }
- function initMenu()
- {
- if(typeof(config.layout) != "undefined")
- {
- $('.list-unstyled li').each(function(j)
- {
- $(this).unbind('click').bind('click', function()
- {
- $('.list-unstyled .active').each(function()
- {
- $(this).attr('class', '');
- $(this).find('a').attr('class', '');
- })
- $(this).attr('class', 'active');
- var a = $(this).find('a');
- a.attr('class', 'subdrop');
- //alert($(this).attr('class'));
- })
- });
- $('.project-list').each(function()
- {
- $(this).unbind('click').bind('click', function()
- {
- $('.project-list').each(function()
- {
- $(this).find('i').parent().attr('class', '');
- $(this).find('ul').attr('class', 'list-unstyled upload-menu');
- })
- $(this).find('i').parent().attr('class', 'active');
- $(this).find('ul').attr('class', 'list-unstyled upload-menu in');
- })
- });
- }
- }
- function table()
- {
- $('[data-pattern]').each(function ()
- {
- var $tableScrollWrapper = $(this);
- $tableScrollWrapper.responsiveTable($tableScrollWrapper.data());
- });
- }
- function initDate()
- {
- $.datetimepicker.setLocale('ch');
- if($(".manage_time").length)
- {
- $(".manage_time").each(function()
- {
- $(this).datetimepicker(
- {
- //inline:true,
- timepicker:false,
- format:'Y-m-d',
- lang:'ch'
- });
- });
- }
-
- if($(".manage_date").length)
- {
- $(".manage_date").each(function()
- {
- $(this).datetimepicker(
- {
- //datepicker:false,
- format:'Y-m-d H:i:s',
- lang:'ch'
- });
- });
- }
- }
- function initPic()
- {
- $('a[rel]').fancybox();
- }
- 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');
- var toolbar = [
- 'title'
- ,'bold'
- ,'italic'
- ,'underline'
- ,'strikethrough'
- ,'fontScale'
- ,'color'
- ,'ol'
- ,'ul'
- ,'blockquote'
- ,'code'
- ,'table'
- ,'link'
- ,'image'
- ,'hr'
- ,'indent'
- ,'outdent'
- ,'alignment'
- //,'emoji'
- , '|'
- ,'html'
- ];
- if(typeof(editors[id]) == "object")
- {
- editors[id].destroy();
- editors[id] = undefined;
- }
- if(typeof(editors[id]) == "undefined")
- {
- editors[id] = new Simditor(
- {
- textarea: e,
- upload:
- {
- url: config.upload + '.simditor',
- params: {key:key},
- fileKey: 'file',
- connectionCount: 10,
- leaveConfirm: 'Uploading is in progress, are you sure to leave this page?'
- },
- toolbar : toolbar,
- emoji:
- {
- imagePath: config.lib + 'simditor/plugins/emoji/images/emoji/'
- }
- });
- }
- }
- //更新页面的提交按钮
- function submit()
- {
- if($(".save-data").length)
- {
- $(".save-data").unbind('click').bind('click', function()
- {
- submit_action();
- //$(this).unbind('click');
- })
- }
- }
- //设置某一个input的值
- function set_update(id, value)
- {
- if($(id).length)
- {
- $(id).val(value);
- }
- }
- /**
- * 批量复制数据
- */
- function copy_data(e)
- {
- var html = '<div>';
- html += '<div><span>请输入要复制的数量:</span><input type="text" class="form-control form_margin" id="temp_copy_num" /></div>';
- html += '</div>';
- $('#dever_modal_body').html(html);
-
- $('#dever_modal_title').html('复制数据');
-
- $("#dever_modal_yes").unbind('click').bind('click', function()
- {
- set_update('#copy_num', $("#temp_copy_num").val());
- set_update('#update_where_id', 0);
- submit_action();
- });
- }
- //直接提交更新页的数据
- function submit_action()
- {
- $(".form1").submit();
- }
- //头部菜单
- 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'))
- {
- inputShow($(this), $(this).attr('show_id'));
- }
- })
- }
- }
- 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').replace('up_col_', '');
- 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('操作已成功!您的操作已修改当前选项!');
- preview();
- })
- }
- 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);
- }
- }
- //根据e的值,来载入其他数据
- function loading(e, data)
- {
- var value = e.val();
- if(e.attr('id') && e.attr('id').indexOf('_temp') != -1)
- {
- var id = e.attr('id').replace('_temp', '');
- if($('#' + id).length)
- {
- var value = $('#' + id).val();
- }
- }
- if(data.element)
- {
- if(data.url)
- {
- data.value = value;
- $.getJSON(data.url, data, function(t)
- {
- $('#update_'+data.element+'_value').val(t.data);
- });
- }
- else
- {
- $('#update_'+data.element+'_value').val(value);
- }
- }
- else if(data.url)
- {
- data.value = value;
- data.where_id = $('#update_where_id').val();
- data.table = $('#table').val();
- data.key = $('#key').val();
- $.getJSON(data.url, data, function(s)
- {
- t = s.data;
- if(t.indexOf('onblur') != -1)
- {
- eval(t);
- }
- else
- {
- var parent = e.parent().parent();
- if(t.indexOf('status') == -1)
- {
- if(data.type == 1)
- {
- $('.checking_1,.checking_2,.checking_3,.checking_4').each(function()
- {
- $(this).remove();
- });
- }
- else
- {
- $('.checking_-1,.checking_3,.checking_4').each(function()
- {
- $(this).remove();
- });
- }
- parent.after(t);
- checkbox();
- }
- }
- });
- }
- }
- //根据e的值,来载入其他数据,先检测是否选中
- function checking(name, e, data)
- {
- var value = [];
- $('.' + name).each(function()
- {
- if($(this).get(0).checked == true)
- {
- value.push($(this).val());
- }
- });
- if(data.url)
- {
- data.value = value.join(',');
- data.where_id = $('#update_where_id').val();
- data.table = $('#table').val();
- data.key = $('#key').val();
- if(data.check)
- {
- data.check_value = false;
- $(data.check).each(function()
- {
- if($(this).get(0).checked == true)
- {
- data.check_value = $(this).val();
- }
- });
- }
- $.getJSON(data.url, data, function(s)
- {
- t = s.data;
- var parent = e.parent().parent().parent();
- if(t.indexOf('status') == -1)
- {
- if(data.type == 1)
- {
- $('.checking_1,.checking_2,.checking_3,.checking_4').each(function()
- {
- $(this).remove();
- });
- }
- else
- {
- $('.checking_-1,.checking_3,.checking_4').each(function()
- {
- $(this).remove();
- });
- }
- parent.after(t);
- checkbox();
- }
- });
- }
- }
- 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;
- var state = true;
- for(var i in data)
- {
- if(data[i].id <=0)
- {
- state = false;
- }
- }
- if(state)
- {
- response( data );
- }
- });
- },
- select: function( event, ui )
- {
- //log( "Selected: " + ui.item.value + " aka " + ui.item.id );
- var value = self.attr('complete_callback');
- var id = self.attr('id').replace('_temp', '');
- $("#" + id).val(ui.item[value]);
- }
- });
- })
- }
- }
- //后台通用的提示
- function msg(value)
- {
- if(value == 1)
- {
- location.reload();
- return;
- }
- submit();
- var url = '';
- if(value.msg != 'reload' && value.status == 2)
- {
- //showAlert(value.msg);
- alert(value.msg);
- //location.reload();
- return;
- }
- else if(value.msg == 'reload')
- {
- if(typeof(config.layout) != "undefined" && $(config.layout).length)
- {
- $.pjax({url: location.href, container: config.layout});
- }
- else
- {
- 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)
- {
- if(typeof(config.layout) != "undefined" && $(config.layout).length)
- {
- $.pjax({url: url, container: config.layout});
- }
- else
- {
- location.href = url;
- }
- }
- else
- {
- if(typeof(config.layout) != "undefined" && $(config.layout).length)
- {
- $.pjax({url: location.href, container: config.layout});
- }
- else
- {
- location.reload();
- }
- }
- }
-
- return;
- }
- /**
- * 处理多选问题,处理全选按钮
- */
- function checkbox()
- {
- if($(".autoload").length)
- {
- $(".autoload").each(function()
- {
- if($(this).get(0).checked == true)
- {
- $(this).removeClass('autoload');
- $(this).load();
- }
- });
- }
- if($(".autoload_text").length)
- {
- $(".autoload_text").each(function()
- {
- if($(this).val())
- {
- $(this).removeClass('autoload_text');
- $(this).load();
- }
- });
- }
- 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_col()
- {
- if($(".edit_col").length)
- {
- $(".edit_col").each(function()
- {
- $(this).bind('blur', function()
- {
- var self = $(this);
- 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 value = self.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('修改成功');
- //preview();
- /*
- if(type && type == 'textarea')
- {
- self.html(t);
- }
- */
- })
- });
- })
- }
- }
- /**
- * 处理双击编辑
- */
- function edit()
- {
- edit_col();
- 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="10" cols="60">'+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('修改成功');
- preview();
- /*
- if(type && type == 'textarea')
- {
- self.html(t);
- }
- */
- })
- })
- }
- });
- })
- }
- }
- function preview()
- {
- if($("#preview").length)
- {
- var time = Date.parse(new Date());
- var src = $('#preview').attr('src').split('#');
- $('#preview').attr('src', src[0] + '&' + time + '#' + src[1]);
- }
- }
- 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 + '?json=1&callback=?', {}, function(t)
- {
- msg(t);
- })
- }
- }
- /**
- * 处理特殊加载的按钮
- */
- function load(href)
- {
- if(confirm('确定进行此项操作吗?'))
- {
- if(href.indexOf('&') == -1)
- {
- href += '?json=1&callback=?';
- }
- else
- {
- href += '&json=1&callback=?';
- }
- $.getJSON(href, {}, function(t)
- {
- msg(t);
- //location.reload();
- })
- }
- /*
- showAlert('确定进行此项操作吗?', function()
- {
- $("#dever_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($(".dever-note").length)
- {
- $(".dever-note").each(function()
- {
- var key = $(this).attr('key');
- $(this).inlineattachment(
- {
- uploadUrl: config.upload + '.drag?key='+ key
- });
- });
- }
- 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 form_margin" id="edit_old_password" /></div>';
- html += '<div><span>新密码:</span><input type="password" class="form-control form_margin" id="edit_new_password" /></div>';
- html += '</div>';
- $('#dever_modal_body').html(html);
-
- $('#dever_modal_title').html('修改密码');
-
- $("#dever_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);
- $("#dever_modal_no").click();
- })
- })
- }
- var MSG = [];
- /**
- * 打开弹窗
- */
- //function showMsg(title, e, id, func)
- function showMsg(title, e, id, func)
- {
- if(id.indexOf('http://') == -1)
- {
- if($(id).length)
- {
- var html = $(id).html();
-
- if($(id).html())
- {
- var html = $(id).html();
- MSG[id] = html;
- $(id).html('');
- }
- else
- {
- var html = MSG[id];
- }
- }
- else
- {
- var html = id;
- }
- $('#dever_modal_body').html(html);
-
- $('#dever_modal_title').html(title);
-
- if(func)
- {
- $("#dever_modal_yes").unbind('click').bind('click', func);
- }
- }
- else
- {
- if(e)
- {
- data = e.attr('msg-send');
- }
- $.getJSON(id+'?json=1',{data:data},function(t)
- {
- t = t.data;
- $('#dever_modal_body').html(t);
-
- $('#dever_modal_title').html(title);
-
- if(func)
- {
- $("#dever_modal_yes").unbind('click').bind('click', func);
- }
- });
- }
- }
- function updateMsg(id)
- {
- $("#"+id).submit();
- }
- function showAlert(msg, func)
- {
- //$("#dever_modal_no").click();
- $("#dever_modal").modal();
- $('#dever_modal_body').html(msg);
-
- $('#dever_modal_title').html('提醒您');
-
- if(func)
- {
- $("#dever_modal_yes").unbind('click').bind('click', func);
- }
- else
- {
- $("#dever_modal_yes").unbind('click').bind('click', function(){$("#dever_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'));
- }
- function select_mul(level, id, url, name, value, valid, w, num)
- {
- if(level == 0)
- {
- $(id).find('select').remove();
- $(id).find('span').remove();
- return;
- }
- var parent = value.split(',');
- var cur = parent[0];
- parent.remove(cur);
- value = parent.join(',');
- var html = '';
- var old = level;
- if(level != -1)
- {
- if($(id + '_' + level).length)
- {
- level = $(id + '_' + level).val();
- }
- if(level == 0)
- {
- $(id + '_' + old).nextAll('select').remove();
- $(id + '_' + old).next('span').nextAll('span').remove();
- if($('#' + name + '_level_value').length)
- {
- var total = $(id).find('select').length;
- $('#' + name + '_level_value').val(total);
- }
- if(old == -2 && $('#' + name + '_value_value').length)
- {
- $('#' + name + '_value_value').val(level);
- }
- return;
- }
- if(old == -2)
- {
- $(id + '_' + old).nextAll('select').remove();
- $(id + '_' + old).next('span').nextAll('span').remove();
- }
- if($('#' + name + '_value_value').length)
- {
- $('#' + name + '_value_value').val(level);
- }
- }
- var total = $(id).find('select').length;
- if(num > 0 && total >= num)
- {
- return;
- }
- var get = url.replace('{level}', level);
- if(level == -1)
- {
- level = -2;
- }
- if(!$(id + '_' + level).length)
- {
- $.getJSON(get + '&json=1', function(t)
- {
- var check = '';
- if(!t.status)
- {
- html = '<select style="'+w+'display:inline;margin-top:10px;" class="update_value form-control '+valid+' dever-mul-'+name+'_'+level+'" name="'+name+'[]" onchange="select_mul('+level+', \''+id+'\', \''+url+'\', \''+name+'\', \''+value+'\', \''+valid+'\', \''+w+'\', '+num+');">';
- for(a in t.data)
- {
- if(t.data[a].value)
- {
- check = '';
- if(cur == t.data[a].value)
- {
- check = ' selected';
- }
- html += '<option value="'+t.data[a].value+'" '+check+'>'+t.data[a].name+'</option>';
- }
- }
- html += '</select><span> </span>';
- $(id).append(html);
- $(id + '_' + level).change();
- }
- else
- {
- $(id + '_' + old).nextAll('select').remove();
- $(id + '_' + old).next('span').nextAll('span').remove();
- }
- if($('#' + name + '_level_value').length)
- {
- var total = $(id).find('select').length;
- $('#' + name + '_level_value').val(total);
- }
- if($('#' + name + '_up_value').length)
- {
- $('#' + name + '_up_value').val($(id + '_-2').val());
- }
- });
- }
- }
- //处理更新页面的一些功能,写到一起吧
- var dever_update =
- {
- addIndex : 2,
- index : [],
- auto : false,
- save_key : '',
- init : function()
- {
- var self = this;
- // 增加整个更新的表单
- if($(".dever_update_add").length)
- {
- $('.dever_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/dever/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($(".dever_form_add").length)
- {
- $('.dever_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();
- }
- }
-
- if($('.dever-note').length)
- {
- $('.dever-note').each(function()
- {
- var mditor = new Mditor($(this),{
- fixedHeight:true
- });
-
- mditor.openPreview();
- })
- }
- },
-
- 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)
- {
- $(".dever_save").unbind('click').bind('click', function()
- {
- self.recover();
- }).show();
- }
- else
- {
- $(".dever_save").hide();
- self.auto = setInterval(function(){self.save()}, 3000);
- }
- },
-
- del : function()
- {
- var self = this;
- if($(".dever_form_delete").length)
- {
- $('.dever_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 = '.dever_'+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')+' dever_form_add_child">' + content + '</div>';
-
- p.append(content);
-
- self.del();
- //$("html,body").animate({scrollTop:$('.dever_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);
- }
- };
- $.fn.pasteEvents = function( delay ) {
- if (delay == undefined) delay = 20;
- return $(this).each(function() {
- var $el = $(this);
- $el.on("paste", function() {
- $el.trigger("prepaste");
- setTimeout(function() { $el.trigger("postpaste"); }, delay);
- });
- });
- };
- $("textarea").on("postpaste", function()
- {
- if($(this).val().indexOf('<') != -1)
- {
- $(this).val(toMarkdown($(this).val()));
- }
- }).pasteEvents();
-
|