main.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908
  1. //这里的代码是最早写的,很乱,以后整合优化
  2. var editors = [];
  3. var tables = [];
  4. var select = '';
  5. var submitButton = '';
  6. $(document).ready(function()
  7. {
  8. //init();
  9. });
  10. function init()
  11. {
  12. editors = [];
  13. select = '';
  14. edit();
  15. del();
  16. checkbox();
  17. image();
  18. change();
  19. autocomplete();
  20. template();
  21. submit();
  22. loadShow();
  23. initEditor();
  24. initPic();
  25. initDate();
  26. //更新页面一些功能,上边的一些功能等找时间再优化吧
  27. dever_update.init();
  28. hljs.initHighlightingOnLoad();
  29. table();
  30. }
  31. function formData(form)
  32. {
  33. var d = {};
  34. var t = $(form).serializeArray();
  35. var u = '';
  36. $.each(t, function() {
  37. if (this.name.indexOf('search_') != -1) {
  38. d[this.name] = this.value;
  39. u += '&' + this.name + '=' + this.value;
  40. }
  41. });
  42. return [d,u];
  43. }
  44. function initMenu()
  45. {
  46. if(typeof(config.layout) != "undefined")
  47. {
  48. $('.list-unstyled li').each(function(j)
  49. {
  50. $(this).unbind('click').bind('click', function()
  51. {
  52. if ($(this).index() == i) {
  53. //return;
  54. }
  55. $('.list-unstyled .active').each(function()
  56. {
  57. $(this).attr('class', '');
  58. $(this).find('a').attr('class', '');
  59. })
  60. $(this).attr('class', 'active');
  61. var a = $(this).find('a');
  62. a.attr('class', 'subdrop');
  63. //alert($(this).attr('class'));
  64. })
  65. });
  66. /*
  67. $('.project-list').each(function(i)
  68. {
  69. $(this).unbind('click').bind('click', function()
  70. {
  71. if ($(this).index() == i) {
  72. return;
  73. }
  74. $('.project-list').each(function()
  75. {
  76. $(this).find('i').parent().attr('class', '');
  77. $(this).find('ul').attr('class', 'list-unstyled upload-menu');
  78. })
  79. $(this).find('i').parent().attr('class', 'active');
  80. $(this).find('ul').attr('class', 'list-unstyled upload-menu in');
  81. })
  82. });
  83. */
  84. }
  85. }
  86. function setOption(e, id)
  87. {
  88. var s = $("select[name="+id+"]");
  89. var v = s.val();
  90. if (!select) {
  91. select = s.clone();
  92. }
  93. s.find('option[parent]').remove();
  94. //查找出需要显示的option并复制
  95. var options = select.find("option[parent="+e.val()+"]").clone();
  96. //将需要显示的option添加到select中
  97. s.append(options);
  98. //因为option.remove()不会刷新控件,需要将新的option切换上去
  99. //这里排除了options.size() == 0的情况
  100. var state = 2;
  101. s.find('option').each(function()
  102. {
  103. var val = $(this).val();
  104. if (v == val) {
  105. state = 1;
  106. }
  107. });
  108. if (state == 1) {
  109. s.val(v);
  110. } else {
  111. s.val(0);
  112. }
  113. }
  114. function table()
  115. {
  116. if ($('.table-responsive').length) {
  117. $('.table-responsive[data-pattern]').each(function()
  118. {
  119. $(this).responsiveTable('update');
  120. });
  121. }
  122. }
  123. function pjax(param)
  124. {
  125. param.timeout = 8000;
  126. $.pjax(param);
  127. }
  128. function initDate()
  129. {
  130. $.datetimepicker.setLocale('ch');
  131. if($(".manage_time").length)
  132. {
  133. $(".manage_time").each(function()
  134. {
  135. $(this).datetimepicker(
  136. {
  137. //inline:true,
  138. timepicker:false,
  139. format:'Y-m-d',
  140. lang:'ch'
  141. });
  142. });
  143. }
  144. if($(".manage_date").length)
  145. {
  146. $(".manage_date").each(function()
  147. {
  148. $(this).datetimepicker(
  149. {
  150. //datepicker:false,
  151. format:'Y-m-d H:i:s',
  152. lang:'ch'
  153. });
  154. });
  155. }
  156. }
  157. function initPic()
  158. {
  159. $('a[rel]').fancybox();
  160. }
  161. function initEditor()
  162. {
  163. if($('.editor').length)
  164. {
  165. $('.editor').each(function()
  166. {
  167. var parent = $(this).parent().parent();
  168. //alert(parent.attr('id'));
  169. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  170. {
  171. return;
  172. }
  173. loadEditor($(this));
  174. //loadKEditor($(this));
  175. })
  176. }
  177. }
  178. function loadKEditor(e)
  179. {
  180. if(!e.length)
  181. {
  182. return;
  183. }
  184. var id = e.attr('id');
  185. var key = e.attr('key');
  186. if(typeof(editors[id]) == "object")
  187. {
  188. editors[id] = undefined;
  189. }
  190. if(typeof(editors[id]) == "undefined")
  191. {
  192. var key = e.attr('key');
  193. var param = {
  194. allowImageUpload: true, //上传图片框本地上传的功能,false为隐藏,默认为true
  195. allowImageRemote : false, //上传图片框网络图片的功能,false为隐藏,默认为true
  196. allowFileManager : false, //浏览图片空间
  197. filterMode : false, //HTML特殊代码过滤
  198. themeType : 'simple',
  199. filePostName : 'file',
  200. uploadJson : config.upload + '.kindeditor?key=' + key,
  201. fileManagerJson : config.upload + '.kindeditorFile?key=' + key
  202. /*,
  203. items : [
  204. 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
  205. 'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
  206. 'insertunorderedlist', '|', 'emoticons', 'image', 'link', 'lineheight']
  207. */
  208. }
  209. KindEditor.ready(function(K) {
  210. editors[id] = K.create('#' + id, param);
  211. });
  212. }
  213. }
  214. function loadEditor(e)
  215. {
  216. //return loadKEditor(e);
  217. if(!e.length)
  218. {
  219. return;
  220. }
  221. var id = e.attr('id');
  222. var key = e.attr('key');
  223. var toolbar = [
  224. 'title'
  225. ,'bold'
  226. ,'italic'
  227. ,'underline'
  228. ,'strikethrough'
  229. ,'fontScale'
  230. ,'color'
  231. ,'ol'
  232. ,'ul'
  233. ,'blockquote'
  234. ,'code'
  235. ,'table'
  236. ,'link'
  237. ,'image'
  238. ,'hr'
  239. ,'indent'
  240. ,'outdent'
  241. ,'alignment'
  242. //,'emoji'
  243. , '|'
  244. ,'html'
  245. ];
  246. if(typeof(editors[id]) == "object")
  247. {
  248. //editors[id].destroy();
  249. //editors[id] = undefined;
  250. }
  251. if(typeof(editors[id]) == "undefined")
  252. {
  253. editors[id] = new Simditor(
  254. {
  255. textarea: e,
  256. upload:
  257. {
  258. url: config.upload + '.simditor',
  259. params: {key:key},
  260. fileKey: 'file',
  261. connectionCount: 10,
  262. leaveConfirm: 'Uploading is in progress, are you sure to leave this page?'
  263. },
  264. toolbar : toolbar,
  265. emoji:
  266. {
  267. imagePath: config.lib + 'simditor/plugins/emoji/images/emoji/'
  268. }
  269. });
  270. }
  271. }
  272. //更新页面的提交按钮
  273. function submit()
  274. {
  275. if($(".save-data").length)
  276. {
  277. if (submitButton) {
  278. $(".save-data").each(function()
  279. {
  280. $(this).html(submitButton);
  281. })
  282. }
  283. $(".save-data").unbind('click').bind('click', function()
  284. {
  285. submitButton = $(this).html();
  286. $(this).html('loading...');
  287. $(this).unbind('click');
  288. submit_action();
  289. })
  290. }
  291. }
  292. //直接提交更新页的数据
  293. function submit_action()
  294. {
  295. $(".form1").submit();
  296. }
  297. //设置某一个input的值
  298. function set_update(id, value)
  299. {
  300. if($(id).length)
  301. {
  302. $(id).val(value);
  303. }
  304. }
  305. /**
  306. * 批量复制数据
  307. */
  308. function copy_data(e)
  309. {
  310. var html = '<div>';
  311. html += '<div><span>请输入要复制的数量:</span><input type="text" class="form-control form_margin" id="temp_copy_num" /></div>';
  312. html += '</div>';
  313. $('#dever_modal_body').html(html);
  314. $('#dever_modal_title').html('复制数据');
  315. $("#dever_modal_yes").unbind('click').bind('click', function()
  316. {
  317. set_update('#copy_num', $("#temp_copy_num").val());
  318. set_update('#update_where_id', 0);
  319. submit_action();
  320. });
  321. }
  322. //头部菜单
  323. function topMenu(e)
  324. {
  325. var p = e.parent().parent().parent().find('span');
  326. p.html(e.html());
  327. //更新当前的精细权限
  328. var url = config.host + 'top.update_action?json=1';
  329. var id = e.attr('data-id');
  330. $.post(url, {id:id}, function(t)
  331. {
  332. var href = location.href;
  333. if(location.href.indexOf('where_id') != -1)
  334. {
  335. var temp = location.href.split('where_id');
  336. href = temp[0] + 'where_id=' + t;
  337. }
  338. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  339. {
  340. pjax({url: href, container: config.layout})
  341. }
  342. else
  343. {
  344. location.href = href;
  345. }
  346. })
  347. }
  348. //更新页面的批量载入选择
  349. function loadShow()
  350. {
  351. if($(".show_input").length)
  352. {
  353. $(".show_input input").each(function()
  354. {
  355. if($(this).attr('checked'))
  356. {
  357. inputShow($(this), $(this).attr('show_id'));
  358. }
  359. })
  360. $(".show_input select").each(function()
  361. {
  362. if($(this).attr('selected'))
  363. {
  364. inputShow($(this), $(this).attr('show_id'));
  365. }
  366. })
  367. }
  368. }
  369. function inputShow(e,n)
  370. {
  371. var item = e.parent().find('input');
  372. $(".show_" + n).hide();
  373. var array = ['input', 'textarea'];
  374. for(var a in array)
  375. {
  376. if ($(".show_" + n).find(array[a]).length) {
  377. var c = $(".show_" + n).find(array[a]).attr('class');
  378. if (c.indexOf('validate[required]') > -1) {
  379. $(".show_" + n).find(array[a]).removeClass('validate[required]').addClass('validates');
  380. }
  381. }
  382. }
  383. item.each(function()
  384. {
  385. if($(this).get(0).checked == true)
  386. {
  387. inputShowOne($(this),n);
  388. }
  389. });
  390. }
  391. function inputShowOne(e,n)
  392. {
  393. var value = e.val();
  394. //$(".show_" + n).hide();
  395. //$(".show_" + n + '_' + value).attr('style','color:red').show();
  396. $(".show_" + n + '_' + value).show();
  397. var array = ['input', 'textarea'];
  398. for(var a in array)
  399. {
  400. if($(".show_" + n + '_' + value).length && $(".show_" + n + '_' + value).attr('class').indexOf('show_no') == -1)
  401. {
  402. $(".show_" + n + '_' + value).find(array[a]).each(function()
  403. {
  404. var parent = $(this).parent();
  405. if($(this).attr('class') != 'editor' && $(this).attr('class').indexOf('validates') > -1 && parent.find('label').length && parent.find('label').html().indexOf('选填') == -1)
  406. {
  407. $(this).addClass('validate[required]');
  408. }
  409. })
  410. }
  411. }
  412. }
  413. //批量更新
  414. function list_mul(e)
  415. {
  416. var type = parseInt($("#mul_type").val());
  417. if(type != 1 && type != 2)
  418. {
  419. alert('您还没有选择数据更新方式');
  420. return;
  421. }
  422. if(confirm('确定进行此项操作吗?'))
  423. {
  424. //e.html('更新中').unbind('click');
  425. $('#method').val('mul');
  426. $('#function').val('msg');
  427. $('#form1').attr('target', 'f1').submit();
  428. }
  429. }
  430. //搜索
  431. function list_search(e)
  432. {
  433. $('#method').val('search');
  434. $('#function').val('');
  435. $('#form1').attr('target', '').submit();
  436. }
  437. //更新数据
  438. function update(e, id, project, table, notice)
  439. {
  440. var call = function()
  441. {
  442. var col = e.attr('name').replace('up_col_', '');
  443. var value = e.val();
  444. var url = config.host + 'database.update_action?json=1';
  445. $.post(url, {where_id:id,col:col,value:value,project:project,table:table}, function(t)
  446. {
  447. notify('操作已成功!您的操作已修改当前选项!');
  448. preview();
  449. })
  450. }
  451. if(notice && confirm(notice))
  452. {
  453. call();
  454. }
  455. else
  456. {
  457. call();
  458. }
  459. }
  460. function notify(msg)
  461. {
  462. var notice = new PNotify({
  463. title: '提示信息',
  464. text: msg,
  465. buttons: {
  466. closer: false,
  467. sticker: false
  468. }
  469. });
  470. notice.get().click(function() {
  471. notice.remove();
  472. });
  473. }
  474. //模板选择
  475. function template()
  476. {
  477. if(config.template)
  478. {
  479. $('body').attr('class', 'theme-' + config.template);
  480. }
  481. if($(".selector").length)
  482. {
  483. $(".selector").each(function()
  484. {
  485. if($(this).data('check') == 'checked')
  486. {
  487. selector($(this));
  488. }
  489. })
  490. }
  491. }
  492. //选择器
  493. function selector(e)
  494. {
  495. var value = e.data('value');
  496. var name = e.data('name');
  497. $('#'+name+'_value').val(value);
  498. $('.'+name+'_selector').children().css({'border':'1px solid #ccc'});
  499. e.children().css({'border':'1px solid black'});
  500. if(name == 'update_template')
  501. {
  502. $('body').attr('class', 'theme-' + value);
  503. }
  504. }
  505. //根据e的值,来载入其他数据
  506. function loading(e, data)
  507. {
  508. var value = e.val();
  509. if(e.attr('id') && e.attr('id').indexOf('_temp') != -1)
  510. {
  511. var id = e.attr('id').replace('_temp', '');
  512. if($('#' + id).length)
  513. {
  514. var value = $('#' + id).val();
  515. }
  516. }
  517. if(data.element)
  518. {
  519. if(data.url)
  520. {
  521. data.value = value;
  522. $.getJSON(data.url, data, function(t)
  523. {
  524. $('#update_'+data.element+'_value').val(t.data);
  525. });
  526. }
  527. else
  528. {
  529. $('#update_'+data.element+'_value').val(value);
  530. }
  531. }
  532. else if(data.url)
  533. {
  534. data.value = value;
  535. data.where_id = $('#update_where_id').val();
  536. data.table = $('#table').val();
  537. data.project = $('#project').val();
  538. $.getJSON(data.url, data, function(s)
  539. {
  540. t = s.data;
  541. if(t.indexOf('onblur') != -1)
  542. {
  543. eval(t);
  544. }
  545. else
  546. {
  547. var parent = e.parent().parent();
  548. if(t.indexOf('status') == -1)
  549. {
  550. if(data.type == 1)
  551. {
  552. $('.checking_1,.checking_2,.checking_3,.checking_4').each(function()
  553. {
  554. $(this).remove();
  555. });
  556. }
  557. else
  558. {
  559. $('.checking_-1,.checking_3,.checking_4').each(function()
  560. {
  561. $(this).remove();
  562. });
  563. }
  564. parent.after(t);
  565. checkbox();
  566. }
  567. }
  568. });
  569. }
  570. }
  571. //根据e的值,来载入其他数据,先检测是否选中
  572. function checking(name, e, data)
  573. {
  574. var value = [];
  575. $('.' + name).each(function()
  576. {
  577. if($(this).get(0).checked == true)
  578. {
  579. value.push($(this).val());
  580. }
  581. });
  582. if(data.url)
  583. {
  584. data.value = value.join(',');
  585. data.where_id = $('#update_where_id').val();
  586. data.table = $('#table').val();
  587. data.project = $('#project').val();
  588. if(data.check)
  589. {
  590. data.check_value = false;
  591. $(data.check).each(function()
  592. {
  593. if($(this).get(0).checked == true)
  594. {
  595. data.check_value = $(this).val();
  596. }
  597. });
  598. }
  599. $.getJSON(data.url, data, function(s)
  600. {
  601. t = s.data;
  602. var parent = e.parent().parent().parent();
  603. if(t.indexOf('status') == -1)
  604. {
  605. if(data.type == 1)
  606. {
  607. $('.checking_1,.checking_2,.checking_3,.checking_4').each(function()
  608. {
  609. $(this).remove();
  610. });
  611. }
  612. else
  613. {
  614. $('.checking_-1,.checking_3,.checking_4').each(function()
  615. {
  616. $(this).remove();
  617. });
  618. }
  619. parent.after(t);
  620. checkbox();
  621. }
  622. });
  623. }
  624. }
  625. function autocomplete()
  626. {
  627. if($("input[complete]").length)
  628. {
  629. $("input[complete]").each(function()
  630. {
  631. var cache = {};
  632. var self = $(this);
  633. self.autocomplete(
  634. {
  635. minLength: 2,
  636. source: function( request, response )
  637. {
  638. var term = request.term;
  639. if ( term in cache ) {
  640. response( cache[ term ] );
  641. return;
  642. }
  643. $.getJSON(self.attr('complete') + '&callback=?', request, function( data, status, xhr ) {
  644. console.info(data);
  645. cache[ term ] = data;
  646. var state = true;
  647. for(var i in data)
  648. {
  649. if(data[i].id <=0)
  650. {
  651. state = false;
  652. }
  653. }
  654. if(state)
  655. {
  656. response( data );
  657. }
  658. });
  659. },
  660. select: function( event, ui )
  661. {
  662. //log( "Selected: " + ui.item.value + " aka " + ui.item.id );
  663. var value = self.attr('complete_callback');
  664. var id = self.attr('id').replace('_temp', '');
  665. $("#" + id).val(ui.item[value]);
  666. }
  667. });
  668. })
  669. }
  670. }
  671. //后台通用的提示
  672. function msg(value)
  673. {
  674. $("#dever_modal_no").click();
  675. if(!value.data)
  676. {
  677. value.data = value.msg;
  678. }
  679. if(value == 1)
  680. {
  681. location.reload();
  682. return;
  683. }
  684. submit();
  685. var url = '';
  686. if(value.data != 'reload' && value.status == 2)
  687. {
  688. showAlert(value.msg, false, '错误提示');
  689. //alert(value.data);
  690. //location.reload();
  691. return;
  692. }
  693. else if(value.data == 'reload')
  694. {
  695. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  696. {
  697. pjax({url: location.href, container: config.layout})
  698. }
  699. else
  700. {
  701. location.reload();
  702. }
  703. return;
  704. }
  705. else
  706. {
  707. if(value.data.indexOf('http://') != -1)
  708. {
  709. url = value.data;
  710. }
  711. else if($("#url").length)
  712. {
  713. url = $("#url").val();
  714. }
  715. else
  716. {
  717. notify(value.data)
  718. return;
  719. }
  720. if(url)
  721. {
  722. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  723. {
  724. pjax({url: url, container: config.layout});
  725. }
  726. else
  727. {
  728. location.href = url;
  729. }
  730. }
  731. else
  732. {
  733. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  734. {
  735. pjax({url: location.href, container: config.layout});
  736. }
  737. else
  738. {
  739. location.reload();
  740. }
  741. }
  742. }
  743. return;
  744. }
  745. /**
  746. * 处理多选问题,处理全选按钮
  747. */
  748. function checkbox()
  749. {
  750. if($(".autoload").length)
  751. {
  752. $(".autoload").each(function()
  753. {
  754. if($(this).get(0).checked == true)
  755. {
  756. $(this).removeClass('autoload');
  757. $(this).load();
  758. }
  759. });
  760. }
  761. if($(".autoload_text").length)
  762. {
  763. $(".autoload_text").each(function()
  764. {
  765. if($(this).val())
  766. {
  767. $(this).removeClass('autoload_text');
  768. $(this).load();
  769. }
  770. });
  771. }
  772. var name = 'checkbox-checkall';
  773. var checkbox = $("." + name);
  774. if(checkbox.length)
  775. {
  776. checkbox.click(function()
  777. {
  778. var self = $(this);
  779. $("." + name + "-" + self.val()).each(function()
  780. {
  781. $(this).get(0).checked = self.get(0).checked;
  782. var next = $(this).next();
  783. if($(this).get(0).checked == true)
  784. {
  785. if(next.length)
  786. {
  787. //next.attr('disabled', false);
  788. }
  789. if($("#mul_type").length)
  790. {
  791. $("#mul_type").val(1);
  792. }
  793. }
  794. else
  795. {
  796. if(next.length)
  797. {
  798. //next.attr('disabled', true);
  799. }
  800. if($("#mul_type").length)
  801. {
  802. $("#mul_type").val(0);
  803. }
  804. }
  805. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
  806. inputShow($(this), 'col');
  807. }
  808. })
  809. });
  810. checkbox.each(function()
  811. {
  812. var self = $(this);
  813. $("." + name + "-" + self.val()).each(function()
  814. {
  815. $(this).click(function()
  816. {
  817. var next = $(this).next();
  818. if($(this).get(0).checked == true)
  819. {
  820. self.get(0).checked = true;
  821. if(self.attr('type') == 'radio')
  822. {
  823. //如果父选项是radio类型,做下限制
  824. //alert(1);
  825. }
  826. if($("#mul_type").length)
  827. {
  828. $("#mul_type").val(1);
  829. }
  830. if(next.length)
  831. {
  832. next.attr('disabled', false);
  833. }
  834. }
  835. else
  836. {
  837. //子选项取消时,处理一下父级选项
  838. var num = 0;
  839. $("." + name + "-" + self.val()).each(function()
  840. {
  841. if($(this).get(0).checked == true)
  842. {
  843. num = 1;
  844. }
  845. });
  846. if(num == 0)
  847. {
  848. self.get(0).checked = false;
  849. if($("#mul_type").length)
  850. {
  851. $("#mul_type").val(0);
  852. }
  853. }
  854. if(next.length)
  855. {
  856. next.attr('disabled', true);
  857. }
  858. }
  859. })
  860. if($(this).get(0).checked == true)
  861. {
  862. self.get(0).checked = true;
  863. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
  864. inputShow($(this), 'col');
  865. }
  866. }
  867. });
  868. })
  869. }
  870. }
  871. /**
  872. * 处理双击编辑
  873. */
  874. function edit()
  875. {
  876. if($(".edit").length)
  877. {
  878. $(".edit").each(function()
  879. {
  880. $(this).bind('dblclick', function()
  881. {
  882. var col = $(this).attr('data-col');
  883. var project = $(this).attr('data-project');
  884. var table = $(this).attr('data-table');
  885. var url = $(this).attr('data-url');
  886. var id = $(this).attr('data-id');
  887. var html = $(this).attr('data-content');
  888. var type = $(this).attr('data-type');
  889. if($(this).find(".edit-content").length)
  890. {
  891. html = $(this).find(".edit-content").html();
  892. html = html.replace('<!--', '<');
  893. html = html.replace('-->', '>');
  894. }
  895. if(html.indexOf('input') == -1)
  896. {
  897. if(type && type == 'textarea')
  898. {
  899. $(this).html('<textarea type="text" name="edit" id="edit" rows="10" cols="60">'+html+'</textarea>');
  900. }
  901. else
  902. {
  903. $(this).html('<input type="text" name="edit" id="edit" value="'+html+'">');
  904. }
  905. var self = $(this);
  906. self.find("#edit").blur(function()
  907. {
  908. var value = self.find("#edit").val();
  909. if(!value)
  910. {
  911. alert('不能为空');
  912. return;
  913. }
  914. if($(this).find(".edit-content").length)
  915. {
  916. $(this).find(".edit-content").html(value);
  917. }
  918. else
  919. {
  920. self.attr('data-content', value);
  921. }
  922. self.html(value);
  923. $.post(url, {project:project,table:table,value:value,where_id:id,col:col}, function(t)
  924. {
  925. notify('修改成功');
  926. preview();
  927. /*
  928. if(type && type == 'textarea')
  929. {
  930. self.html(t);
  931. }
  932. */
  933. })
  934. })
  935. }
  936. });
  937. })
  938. }
  939. }
  940. function preview()
  941. {
  942. if($("#preview").length)
  943. {
  944. var time = Date.parse(new Date());
  945. var src = $('#preview').attr('src').split('#');
  946. $('#preview').attr('src', src[0] + '&' + time + '#' + src[1]);
  947. }
  948. }
  949. function del()
  950. {
  951. if($(".oper_delete").length)
  952. {
  953. $(".oper_delete").each(function()
  954. {
  955. var href = $(this).attr('href');
  956. $(this).attr('href', '#');
  957. $(this).unbind('click');
  958. $(this).bind('click', function()
  959. {
  960. del_act(href);
  961. });
  962. })
  963. }
  964. }
  965. /**
  966. * 处理删除
  967. */
  968. function del_act(href)
  969. {
  970. if(confirm('确定进行此项操作吗?'))
  971. {
  972. $.getJSON(href + '&json=1&callback=?', {}, function(t)
  973. {
  974. msg(t);
  975. })
  976. }
  977. }
  978. /**
  979. * 处理特殊加载的按钮
  980. */
  981. function load(href)
  982. {
  983. if(confirm('确定进行此项操作吗?'))
  984. {
  985. if(href.indexOf('&') == -1)
  986. {
  987. href += '?json=1&callback=?';
  988. }
  989. else
  990. {
  991. href += '&json=1&callback=?';
  992. }
  993. $.getJSON(href, {}, function(t)
  994. {
  995. msg(t);
  996. //location.reload();
  997. })
  998. }
  999. /*
  1000. showAlert('确定进行此项操作吗?', function()
  1001. {
  1002. $("#dever_modal_no").click();
  1003. $.getJSON(href + '&json=1', {}, function(t)
  1004. {
  1005. msg(t);
  1006. })
  1007. });
  1008. */
  1009. }
  1010. /**
  1011. * 处理特殊加载的按钮
  1012. */
  1013. function jump(href, form)
  1014. {
  1015. if (form) {
  1016. var param = formData(form);
  1017. href += param[1];
  1018. }
  1019. location.href = href;
  1020. }
  1021. /**
  1022. * 处理change
  1023. */
  1024. function change()
  1025. {
  1026. if($(".change").length)
  1027. {
  1028. $(".change").each(function()
  1029. {
  1030. var key = $(this).attr('data-child');
  1031. /*
  1032. $('.' + key).each(function()
  1033. {
  1034. if($(this).find('select option:selected').val())
  1035. {
  1036. $(this).show();
  1037. $('#set_cate_id_child').get(0).value = $(this).attr('parent');
  1038. }
  1039. });
  1040. */
  1041. $(this).change(function()
  1042. {
  1043. $('.' + key).hide();
  1044. var v = $('.' + key + '_' + $(this).val());
  1045. var s = v.find('select');
  1046. s.change(function()
  1047. {
  1048. $('.' + key + '_value').val($(this).val());
  1049. })
  1050. if(v.length)
  1051. {
  1052. $('.' + key + '_value').val(s.val());
  1053. v.show();
  1054. }
  1055. else
  1056. {
  1057. $('.' + key + '_value').val(-1);
  1058. }
  1059. });
  1060. if($(this).val() > 0)
  1061. {
  1062. $(this).change();
  1063. }
  1064. });
  1065. }
  1066. }
  1067. /**
  1068. * 处理图库系统
  1069. */
  1070. function image()
  1071. {
  1072. if($(".dever-note").length)
  1073. {
  1074. $(".dever-note").each(function()
  1075. {
  1076. var key = $(this).attr('key');
  1077. $(this).inlineattachment(
  1078. {
  1079. uploadUrl: config.upload + '.drag?key='+ key
  1080. });
  1081. });
  1082. }
  1083. if($(".image_upload").length)
  1084. {
  1085. $(".image_upload").each(function(i)
  1086. {
  1087. var parent = $(this).parent().parent();
  1088. //alert(parent.attr('id'));
  1089. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  1090. {
  1091. return;
  1092. }
  1093. loadUpload(i,$(this),$(this).attr('key'),config.upload + '.start', config.lib + 'upload/');//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  1094. })
  1095. }
  1096. }
  1097. /**
  1098. * 修改密码
  1099. */
  1100. function pass(e)
  1101. {
  1102. var html = '<style>.password_edit div{margin:10px;}.password_edit input{width:200px;}</style><div class="password_edit">';
  1103. html += '<div><span>旧密码:</span><input type="password" class="form-control form_margin" id="edit_old_password" /></div>';
  1104. html += '<div><span>新密码:</span><input type="password" class="form-control form_margin" id="edit_new_password" /></div>';
  1105. html += '</div>';
  1106. $('#dever_modal_body').html(html);
  1107. $('#dever_modal_title').html('修改密码');
  1108. $("#dever_modal_yes").unbind('click').bind('click', function()
  1109. {
  1110. var old_password = $("#edit_old_password").val();
  1111. var new_password = $("#edit_new_password").val();
  1112. if(!old_password || !new_password)
  1113. {
  1114. alert('请输入密码');
  1115. return;
  1116. }
  1117. if(old_password == new_password)
  1118. {
  1119. alert('旧密码和新密码相同');
  1120. return;
  1121. }
  1122. $.post(config.host + 'auth.password', {old:old_password,new:new_password}, function(t)
  1123. {
  1124. alert(t);
  1125. $("#dever_modal_no").click();
  1126. })
  1127. })
  1128. }
  1129. var MSG = [];
  1130. /**
  1131. * 打开弹窗
  1132. */
  1133. //function showMsg(title, e, id, func)
  1134. function showMsg(title, e, id, func, param)
  1135. {
  1136. if(id.indexOf('http://') == -1)
  1137. {
  1138. if($(id).length)
  1139. {
  1140. var html = $(id).html();
  1141. if($(id).html())
  1142. {
  1143. var html = $(id).html();
  1144. MSG[id] = html;
  1145. $(id).html('');
  1146. }
  1147. else
  1148. {
  1149. var html = MSG[id];
  1150. }
  1151. }
  1152. else
  1153. {
  1154. var html = id;
  1155. }
  1156. $('#dever_modal_body').html(html);
  1157. $('#dever_modal_title').html(title);
  1158. if (func) {
  1159. $("#dever_modal_yes").unbind('click').bind('click', func);
  1160. } else {
  1161. $("#dever_modal_yes").unbind('click').bind('click', function(){$("#dever_modal_no").click()});
  1162. }
  1163. }
  1164. else
  1165. {
  1166. var url = id;
  1167. var send = {};
  1168. if (param) {
  1169. send = param;
  1170. }
  1171. if (e && e.attr('msg-send')) {
  1172. send.data = e.attr('msg-send');
  1173. }
  1174. if (url.indexOf('?') != -1) {
  1175. url = url + '&';
  1176. } else {
  1177. url = url + '?';
  1178. }
  1179. $.getJSON(url+'json=1',send,function(t)
  1180. {
  1181. t = t.data;
  1182. $('#dever_modal_body').html(t);
  1183. $('#dever_modal_title').html(title);
  1184. if(func)
  1185. {
  1186. $("#dever_modal_yes").unbind('click').bind('click', func);
  1187. }
  1188. });
  1189. }
  1190. }
  1191. function updateMsg(id)
  1192. {
  1193. $("#"+id).submit();
  1194. }
  1195. function showAlert(msg, func, title)
  1196. {
  1197. if (!title) {
  1198. title = $("#dever-name").html() + '提醒您';
  1199. }
  1200. //$("#dever_modal_no").click();
  1201. $("#dever_modal").modal();
  1202. $('#dever_modal_body').html(msg);
  1203. $('#dever_modal_title').html(title);
  1204. if(func)
  1205. {
  1206. $("#dever_modal_yes").unbind('click').bind('click', func);
  1207. }
  1208. else
  1209. {
  1210. $("#dever_modal_yes").unbind('click').bind('click', function(){$("#dever_modal_no").click()});
  1211. }
  1212. }
  1213. function fastEdit(e, url, title, col)
  1214. {
  1215. var func = function()
  1216. {
  1217. submit_action();
  1218. };
  1219. var send = {};
  1220. send.col = col;
  1221. $.get(url,send,function(t)
  1222. {
  1223. var html = $(t).find('form').prop("outerHTML");
  1224. var valid = $(t).find('#valid').prop("outerHTML");
  1225. html = html + valid;
  1226. showAlert(html, func, title);
  1227. $('#update_button').hide();
  1228. init();
  1229. });
  1230. }
  1231. /*
  1232. var test =
  1233. {
  1234. refreshPage: false,
  1235. addAjaxFlag: true,
  1236. //添加收藏
  1237. add: function(cfg)
  1238. {
  1239. }
  1240. }
  1241. */
  1242. function showToggle(e)
  1243. {
  1244. var id = e.attr('toggle');
  1245. var child = e.attr('toggle_child');
  1246. var parent = e.parent();
  1247. parent.parent().find('li').removeClass('active');
  1248. parent.addClass('active');
  1249. $(child).fadeOut(100);
  1250. $(id).fadeIn(500);
  1251. loadEditor($(id).find('.editor'));
  1252. }
  1253. function select_linkage(level, id, url, name, value, valid, w, total, search, level_param)
  1254. {
  1255. var e = '#' + id;
  1256. var parent = value.split(',');
  1257. var cur = parent[0];
  1258. parent.remove(cur);
  1259. value = parent.join(',');
  1260. var html = '';
  1261. var old = level;
  1262. if (!total) {
  1263. level_id = 0;
  1264. } else {
  1265. if (level >= total) {
  1266. //$(e).show();
  1267. return;
  1268. }
  1269. level_id = $(e + '_' + level).val();
  1270. level = parseInt(level) + 1;
  1271. }
  1272. $.getJSON(url + '?json=1', {level_search:search, level_id:level_id, level_num:level,level_param:level_param}, function(t) {
  1273. var check = '';
  1274. if (t.status == 1) {
  1275. var total = t.data.level_total;
  1276. var data = t.data.list;
  1277. if(!$(e + '_' + level).length) {
  1278. html = '<select style="'+w+'display:inline;margin-top:10px;" class="update_value form-control '+valid+'" id="'+id+'_'+level+'" name="'+name+'[]" onchange="select_linkage(\''+level+'\', \''+id+'\', \''+url+'\', \''+name+'\', \''+value+'\', \''+valid+'\', \''+w+'\', '+total+', \''+search+'\', \''+level_param+'\');">';
  1279. }
  1280. for (a in data) {
  1281. if (data[a].value) {
  1282. check = '';
  1283. if (cur == data[a].value) {
  1284. check = ' selected';
  1285. }
  1286. html += '<option value="'+data[a].value+'" '+check+'>'+data[a].name+'</option>';
  1287. }
  1288. }
  1289. if(!$(e + '_' + level).length) {
  1290. html += '</select><span>&nbsp;&nbsp;</span>';
  1291. $(e).append(html);
  1292. $(e + '_' + level).change();
  1293. } else {
  1294. $(e + '_' + level).html(html);
  1295. $(e + '_' + level).change();
  1296. }
  1297. } else {
  1298. $(e + '_' + old).nextAll('select').remove();
  1299. $(e + '_' + old).next('span').nextAll('span').remove();
  1300. }
  1301. /*
  1302. if ($('#' + name + '_level_value').length) {
  1303. var total = $(id).find('select').length;
  1304. $('#' + name + '_level_value').val(total);
  1305. }
  1306. if ($('#' + name + '_up_value').length) {
  1307. $('#' + name + '_up_value').val($(id + '_-2').val());
  1308. }
  1309. */
  1310. });
  1311. }
  1312. /*
  1313. function select_mul(level, id, url, name, value, valid, w, num)
  1314. {
  1315. if(level == 0)
  1316. {
  1317. $(id).find('select').remove();
  1318. $(id).find('span').remove();
  1319. return;
  1320. }
  1321. var parent = value.split(',');
  1322. var cur = parent[0];
  1323. parent.remove(cur);
  1324. value = parent.join(',');
  1325. var html = '';
  1326. var old = level;
  1327. if(level != -1)
  1328. {
  1329. if($(id + '_' + level).length)
  1330. {
  1331. level = $(id + '_' + level).val();
  1332. }
  1333. alert(level);
  1334. if(level == 0)
  1335. {
  1336. $(id + '_' + old).nextAll('select').remove();
  1337. $(id + '_' + old).next('span').nextAll('span').remove();
  1338. if($('#' + name + '_level_value').length)
  1339. {
  1340. var total = $(id).find('select').length;
  1341. $('#' + name + '_level_value').val(total);
  1342. }
  1343. if(old == -2 && $('#' + name + '_value_value').length)
  1344. {
  1345. $('#' + name + '_value_value').val(level);
  1346. }
  1347. return;
  1348. }
  1349. if(old == -2)
  1350. {
  1351. $(id + '_' + old).nextAll('select').remove();
  1352. $(id + '_' + old).next('span').nextAll('span').remove();
  1353. }
  1354. if($('#' + name + '_value_value').length)
  1355. {
  1356. $('#' + name + '_value_value').val(level);
  1357. }
  1358. }
  1359. var total = $(id).find('select').length;
  1360. if(num > 0 && total >= num)
  1361. {
  1362. return;
  1363. }
  1364. var get = url.replace('{level}', level);
  1365. if(level == -1)
  1366. {
  1367. level = -2;
  1368. }
  1369. if(!$(id + '_' + level).length)
  1370. {
  1371. $.getJSON(get + '&json=1', {total:total,level:level}, function(t)
  1372. {
  1373. var check = '';
  1374. if(t.status == 1)
  1375. {
  1376. 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+');">';
  1377. console.log(t.data);
  1378. for(a in t.data)
  1379. {
  1380. if(t.data[a].value)
  1381. {
  1382. check = '';
  1383. if(cur == t.data[a].value)
  1384. {
  1385. check = ' selected';
  1386. }
  1387. html += '<option value="'+t.data[a].value+'" '+check+'>'+t.data[a].name+'</option>';
  1388. }
  1389. }
  1390. html += '</select><span>&nbsp;&nbsp;</span>';
  1391. $(id).append(html);
  1392. $(id + '_' + level).change();
  1393. }
  1394. else
  1395. {
  1396. $(id + '_' + old).nextAll('select').remove();
  1397. $(id + '_' + old).next('span').nextAll('span').remove();
  1398. }
  1399. if($('#' + name + '_level_value').length)
  1400. {
  1401. var total = $(id).find('select').length;
  1402. $('#' + name + '_level_value').val(total);
  1403. }
  1404. if($('#' + name + '_up_value').length)
  1405. {
  1406. $('#' + name + '_up_value').val($(id + '_-2').val());
  1407. }
  1408. });
  1409. }
  1410. }
  1411. */
  1412. //处理更新页面的一些功能,写到一起吧
  1413. var dever_update =
  1414. {
  1415. addIndex : 2,
  1416. index : [],
  1417. auto : false,
  1418. save_key : '',
  1419. init : function()
  1420. {
  1421. var self = this;
  1422. self.index = [];
  1423. // 增加整个更新的表单
  1424. if($(".dever_update_add").length)
  1425. {
  1426. $('.dever_update_add').unbind('click').bind('click', function()
  1427. {
  1428. self.add($(this));
  1429. })
  1430. }
  1431. /* 以后再增加 同时更新另外一个表
  1432. if($(".form-add-content").length)
  1433. {
  1434. var url = config.host + 'auth.password';
  1435. var url = 'http://localhost/dever/manage/?database.update?project=weixin&table=message&menu=weixin&menu_id=39&ajax=1';
  1436. $.get(url, function(t)
  1437. {
  1438. $(".form-add-content").html(t);
  1439. init();
  1440. })
  1441. }
  1442. */
  1443. //增加某一部分表单
  1444. if($(".dever_form_add").length)
  1445. {
  1446. $('.dever_form_add').each(function()
  1447. {
  1448. var key = $.attr('toggle_key');
  1449. if(typeof(self.index[key]) == "undefined")
  1450. {
  1451. self.index[key] = 0;
  1452. }
  1453. $(this).unbind('click').bind('click', function()
  1454. {
  1455. self.append($(this));
  1456. })
  1457. })
  1458. self.del();
  1459. }
  1460. // 开启自动保存
  1461. if($("#struct").length)
  1462. {
  1463. var save = $("#struct").attr('save');
  1464. if(save == 'yes')
  1465. {
  1466. //检测
  1467. self.save_key = location.href + 'test';
  1468. self.check();
  1469. }
  1470. }
  1471. if($('.dever-note').length)
  1472. {
  1473. $('.dever-note').each(function()
  1474. {
  1475. var mditor = new Mditor($(this),{
  1476. fixedHeight:true
  1477. });
  1478. mditor.openPreview();
  1479. })
  1480. }
  1481. },
  1482. save : function()
  1483. {
  1484. //var data = $("#data-1").html();
  1485. var data = [];
  1486. $(".update_value").each(function(i)
  1487. {
  1488. if($(this).attr("update_type") == 'checked')
  1489. {
  1490. data[i] = $(this).get(0).checked;
  1491. }
  1492. else if($(this).attr("update_type") == 'html')
  1493. {
  1494. data[i] = $(this).html();
  1495. }
  1496. else if($(this).attr("update_type") == 'src')
  1497. {
  1498. data[i] = $(this).attr('src');
  1499. }
  1500. else
  1501. {
  1502. data[i] = $(this).val();
  1503. }
  1504. });
  1505. store.set(this.save_key, data.join('|||'));
  1506. //console.info(data);
  1507. },
  1508. recover : function()
  1509. {
  1510. if(confirm('确定恢复上次保存的数据吗?'))
  1511. {
  1512. var data = store.get(this.save_key).split('|||');
  1513. if(data)
  1514. {
  1515. var value = $(".update_value");
  1516. for(var k in data)
  1517. {
  1518. var e = value.eq(k);
  1519. if(e.attr('update_type') == 'checked')
  1520. {
  1521. if(data[k] == 'true')
  1522. {
  1523. e.get(0).checked = true;
  1524. }
  1525. else
  1526. {
  1527. e.get(0).checked = false;
  1528. }
  1529. }
  1530. else if(e.attr('update_type') == 'html')
  1531. {
  1532. e.html(data[k]);
  1533. }
  1534. else if(e.attr('update_type') == 'src')
  1535. {
  1536. e.attr('src', data[k]);
  1537. }
  1538. else
  1539. {
  1540. if(e.attr('id'))
  1541. {
  1542. var id = e.attr('id');
  1543. if(typeof(editors[id]) != "undefined")
  1544. {
  1545. editors[id].setContent(data[k]);
  1546. }
  1547. }
  1548. e.val(data[k]);
  1549. }
  1550. }
  1551. store.set(this.save_key, '');
  1552. this.check();
  1553. }
  1554. }
  1555. },
  1556. check : function()
  1557. {
  1558. var data = store.get(this.save_key);
  1559. var self = this;
  1560. if(data)
  1561. {
  1562. $(".dever_save").unbind('click').bind('click', function()
  1563. {
  1564. self.recover();
  1565. }).show();
  1566. }
  1567. else
  1568. {
  1569. $(".dever_save").hide();
  1570. self.auto = setInterval(function(){self.save()}, 3000);
  1571. }
  1572. },
  1573. del : function()
  1574. {
  1575. var self = this;
  1576. if($(".dever_form_delete").length)
  1577. {
  1578. $('.dever_form_delete').each(function()
  1579. {
  1580. $(this).unbind('click').bind('click', function()
  1581. {
  1582. var parent = $(this).parent();
  1583. var id = parent.attr('id');
  1584. var index = parseInt($('#tab-' + id).attr('toggle_id'));
  1585. var key = $('#tab-' + id).attr('toggle_key');
  1586. if(index <= 1 && self.index[key] <= index)
  1587. {
  1588. }
  1589. else if(index <= 1 && self.index[key] > index)
  1590. {
  1591. index = index+1;
  1592. $("#tab-"+key+"-child-" + index).click();
  1593. }
  1594. else
  1595. {
  1596. index = index-1;
  1597. $("#tab-"+key+"-child-" + index).click();
  1598. };
  1599. $('#tab-' + id).parent().remove();
  1600. parent.remove();
  1601. self.index[key]--;
  1602. })
  1603. })
  1604. }
  1605. },
  1606. append : function(e)
  1607. {
  1608. var self = this;
  1609. var key = e.attr('toggle_key');
  1610. var child = '.dever_'+key+'_child';
  1611. if(typeof(self.index[key]) == "undefined")
  1612. {
  1613. self.index[key] = 0;
  1614. }
  1615. if(self.index[key] <= 0)
  1616. {
  1617. self.index[key] = $(child).length;
  1618. }
  1619. if(self.index[key] > 30)
  1620. {
  1621. alert('最多只能增加30条');
  1622. return;
  1623. }
  1624. var p = e.parent();
  1625. var id = key + '-child-' + self.index[key];
  1626. var name = '第' + (self.index[key]) + '条';
  1627. 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>');
  1628. var e = e.parent().parent();
  1629. var n = e.next();
  1630. var p = e.parent();
  1631. var content = n.html();
  1632. content = content.replaceAll('_c_', '_c_' + (self.index[key]-1) + '_i_');
  1633. content = '<div id="'+id+'" style="display:none;" class="'+n.attr('class')+' dever_form_add_child">' + content + '</div>';
  1634. p.append(content);
  1635. $('#update_' + key +'_c_' + (self.index[key]-1) + '_i_' + 'order_value').val(parseInt($('#update_' + key +'_c_' + (self.index[key]-2) + '_i_' + 'order_value').val())+1);
  1636. self.del();
  1637. //$("html,body").animate({scrollTop:$('.dever_form_add_child').eq(this.appendIndex).offset().top},500);
  1638. self.index[key]++;
  1639. image();
  1640. loadShow();
  1641. autocomplete();
  1642. change();
  1643. },
  1644. add : function(e)
  1645. {
  1646. var self = this;
  1647. var p = e.parent();
  1648. var id = 'data-' + this.addIndex;
  1649. var name = '新增数据-' + (this.addIndex-1);
  1650. p.before('<li><a href="#'+id+'" data-toggle="tab">'+name+'</a></li>');
  1651. var content = $("#myTabContent").find('.tab-pane').eq(0).html();
  1652. content = content.replaceAll('update_', 'update_' + this.addIndex + '__');
  1653. content = '<div class="tab-pane fade" id="'+id+'">' + content + '</div>';
  1654. $("#myTabContent").append(content);
  1655. $('#update_' + this.addIndex + '__where_id').val('-1');
  1656. this.addIndex++;
  1657. }
  1658. }
  1659. String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) {
  1660. if (!RegExp.prototype.isPrototypeOf(reallyDo)) {
  1661. return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi": "g")), replaceWith);
  1662. } else {
  1663. return this.replace(reallyDo, replaceWith);
  1664. }
  1665. }
  1666. Array.prototype.remove = function(val) {
  1667. var index = -1;
  1668. for(var i = 0; i < this.length; i++)
  1669. {
  1670. if(this[i] == val)
  1671. {
  1672. index = i;
  1673. }
  1674. }
  1675. if (index > -1) {
  1676. this.splice(index, 1);
  1677. }
  1678. };
  1679. $.fn.pasteEvents = function( delay ) {
  1680. if (delay == undefined) delay = 20;
  1681. return $(this).each(function() {
  1682. var $el = $(this);
  1683. $el.on("paste", function() {
  1684. $el.trigger("prepaste");
  1685. setTimeout(function() { $el.trigger("postpaste"); }, delay);
  1686. });
  1687. });
  1688. };
  1689. $("textarea").on("postpaste", function()
  1690. {
  1691. if($(this).val().indexOf('<') != -1)
  1692. {
  1693. $(this).val(toMarkdown($(this).val()));
  1694. }
  1695. }).pasteEvents();