main.js 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876
  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. if(!value.data)
  675. {
  676. value.data = value.msg;
  677. }
  678. if(value == 1)
  679. {
  680. location.reload();
  681. return;
  682. }
  683. submit();
  684. var url = '';
  685. if(value.data != 'reload' && value.status == 2)
  686. {
  687. showAlert(value.msg, false, '错误提示');
  688. //alert(value.data);
  689. //location.reload();
  690. return;
  691. }
  692. else if(value.data == 'reload')
  693. {
  694. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  695. {
  696. pjax({url: location.href, container: config.layout})
  697. }
  698. else
  699. {
  700. location.reload();
  701. }
  702. return;
  703. }
  704. else
  705. {
  706. if(value.data.indexOf('http://') != -1)
  707. {
  708. url = value.data;
  709. }
  710. else if($("#url").length)
  711. {
  712. url = $("#url").val();
  713. }
  714. else
  715. {
  716. notify(value.data)
  717. return;
  718. }
  719. if(url)
  720. {
  721. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  722. {
  723. pjax({url: url, container: config.layout});
  724. }
  725. else
  726. {
  727. location.href = url;
  728. }
  729. }
  730. else
  731. {
  732. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  733. {
  734. pjax({url: location.href, container: config.layout});
  735. }
  736. else
  737. {
  738. location.reload();
  739. }
  740. }
  741. }
  742. return;
  743. }
  744. /**
  745. * 处理多选问题,处理全选按钮
  746. */
  747. function checkbox()
  748. {
  749. if($(".autoload").length)
  750. {
  751. $(".autoload").each(function()
  752. {
  753. if($(this).get(0).checked == true)
  754. {
  755. $(this).removeClass('autoload');
  756. $(this).load();
  757. }
  758. });
  759. }
  760. if($(".autoload_text").length)
  761. {
  762. $(".autoload_text").each(function()
  763. {
  764. if($(this).val())
  765. {
  766. $(this).removeClass('autoload_text');
  767. $(this).load();
  768. }
  769. });
  770. }
  771. var name = 'checkbox-checkall';
  772. var checkbox = $("." + name);
  773. if(checkbox.length)
  774. {
  775. checkbox.click(function()
  776. {
  777. var self = $(this);
  778. $("." + name + "-" + self.val()).each(function()
  779. {
  780. $(this).get(0).checked = self.get(0).checked;
  781. var next = $(this).next();
  782. if($(this).get(0).checked == true)
  783. {
  784. if(next.length)
  785. {
  786. //next.attr('disabled', false);
  787. }
  788. if($("#mul_type").length)
  789. {
  790. $("#mul_type").val(1);
  791. }
  792. }
  793. else
  794. {
  795. if(next.length)
  796. {
  797. //next.attr('disabled', true);
  798. }
  799. if($("#mul_type").length)
  800. {
  801. $("#mul_type").val(0);
  802. }
  803. }
  804. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
  805. inputShow($(this), 'col');
  806. }
  807. })
  808. });
  809. checkbox.each(function()
  810. {
  811. var self = $(this);
  812. $("." + name + "-" + self.val()).each(function()
  813. {
  814. $(this).click(function()
  815. {
  816. var next = $(this).next();
  817. if($(this).get(0).checked == true)
  818. {
  819. self.get(0).checked = true;
  820. if(self.attr('type') == 'radio')
  821. {
  822. //如果父选项是radio类型,做下限制
  823. //alert(1);
  824. }
  825. if($("#mul_type").length)
  826. {
  827. $("#mul_type").val(1);
  828. }
  829. if(next.length)
  830. {
  831. next.attr('disabled', false);
  832. }
  833. }
  834. else
  835. {
  836. //子选项取消时,处理一下父级选项
  837. var num = 0;
  838. $("." + name + "-" + self.val()).each(function()
  839. {
  840. if($(this).get(0).checked == true)
  841. {
  842. num = 1;
  843. }
  844. });
  845. if(num == 0)
  846. {
  847. self.get(0).checked = false;
  848. if($("#mul_type").length)
  849. {
  850. $("#mul_type").val(0);
  851. }
  852. }
  853. if(next.length)
  854. {
  855. next.attr('disabled', true);
  856. }
  857. }
  858. })
  859. if($(this).get(0).checked == true)
  860. {
  861. self.get(0).checked = true;
  862. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
  863. inputShow($(this), 'col');
  864. }
  865. }
  866. });
  867. })
  868. }
  869. }
  870. /**
  871. * 处理双击编辑
  872. */
  873. function edit()
  874. {
  875. if($(".edit").length)
  876. {
  877. $(".edit").each(function()
  878. {
  879. $(this).bind('dblclick', function()
  880. {
  881. var col = $(this).attr('data-col');
  882. var project = $(this).attr('data-project');
  883. var table = $(this).attr('data-table');
  884. var url = $(this).attr('data-url');
  885. var id = $(this).attr('data-id');
  886. var html = $(this).attr('data-content');
  887. var type = $(this).attr('data-type');
  888. if($(this).find(".edit-content").length)
  889. {
  890. html = $(this).find(".edit-content").html();
  891. html = html.replace('<!--', '<');
  892. html = html.replace('-->', '>');
  893. }
  894. if(html.indexOf('input') == -1)
  895. {
  896. if(type && type == 'textarea')
  897. {
  898. $(this).html('<textarea type="text" name="edit" id="edit" rows="10" cols="60">'+html+'</textarea>');
  899. }
  900. else
  901. {
  902. $(this).html('<input type="text" name="edit" id="edit" value="'+html+'">');
  903. }
  904. var self = $(this);
  905. self.find("#edit").blur(function()
  906. {
  907. var value = self.find("#edit").val();
  908. if(!value)
  909. {
  910. alert('不能为空');
  911. return;
  912. }
  913. if($(this).find(".edit-content").length)
  914. {
  915. $(this).find(".edit-content").html(value);
  916. }
  917. else
  918. {
  919. self.attr('data-content', value);
  920. }
  921. self.html(value);
  922. $.post(url, {project:project,table:table,value:value,where_id:id,col:col}, function(t)
  923. {
  924. notify('修改成功');
  925. preview();
  926. /*
  927. if(type && type == 'textarea')
  928. {
  929. self.html(t);
  930. }
  931. */
  932. })
  933. })
  934. }
  935. });
  936. })
  937. }
  938. }
  939. function preview()
  940. {
  941. if($("#preview").length)
  942. {
  943. var time = Date.parse(new Date());
  944. var src = $('#preview').attr('src').split('#');
  945. $('#preview').attr('src', src[0] + '&' + time + '#' + src[1]);
  946. }
  947. }
  948. function del()
  949. {
  950. if($(".oper_delete").length)
  951. {
  952. $(".oper_delete").each(function()
  953. {
  954. var href = $(this).attr('href');
  955. $(this).attr('href', '#');
  956. $(this).unbind('click');
  957. $(this).bind('click', function()
  958. {
  959. del_act(href);
  960. });
  961. })
  962. }
  963. }
  964. /**
  965. * 处理删除
  966. */
  967. function del_act(href)
  968. {
  969. if(confirm('确定进行此项操作吗?'))
  970. {
  971. $.getJSON(href + '&json=1&callback=?', {}, function(t)
  972. {
  973. msg(t);
  974. })
  975. }
  976. }
  977. /**
  978. * 处理特殊加载的按钮
  979. */
  980. function load(href)
  981. {
  982. if(confirm('确定进行此项操作吗?'))
  983. {
  984. if(href.indexOf('&') == -1)
  985. {
  986. href += '?json=1&callback=?';
  987. }
  988. else
  989. {
  990. href += '&json=1&callback=?';
  991. }
  992. $.getJSON(href, {}, function(t)
  993. {
  994. msg(t);
  995. //location.reload();
  996. })
  997. }
  998. /*
  999. showAlert('确定进行此项操作吗?', function()
  1000. {
  1001. $("#dever_modal_no").click();
  1002. $.getJSON(href + '&json=1', {}, function(t)
  1003. {
  1004. msg(t);
  1005. })
  1006. });
  1007. */
  1008. }
  1009. /**
  1010. * 处理特殊加载的按钮
  1011. */
  1012. function jump(href, form)
  1013. {
  1014. if (form) {
  1015. var param = formData(form);
  1016. href += param[1];
  1017. }
  1018. location.href = href;
  1019. }
  1020. /**
  1021. * 处理change
  1022. */
  1023. function change()
  1024. {
  1025. if($(".change").length)
  1026. {
  1027. $(".change").each(function()
  1028. {
  1029. var key = $(this).attr('data-child');
  1030. /*
  1031. $('.' + key).each(function()
  1032. {
  1033. if($(this).find('select option:selected').val())
  1034. {
  1035. $(this).show();
  1036. $('#set_cate_id_child').get(0).value = $(this).attr('parent');
  1037. }
  1038. });
  1039. */
  1040. $(this).change(function()
  1041. {
  1042. $('.' + key).hide();
  1043. var v = $('.' + key + '_' + $(this).val());
  1044. var s = v.find('select');
  1045. s.change(function()
  1046. {
  1047. $('.' + key + '_value').val($(this).val());
  1048. })
  1049. if(v.length)
  1050. {
  1051. $('.' + key + '_value').val(s.val());
  1052. v.show();
  1053. }
  1054. else
  1055. {
  1056. $('.' + key + '_value').val(-1);
  1057. }
  1058. });
  1059. if($(this).val() > 0)
  1060. {
  1061. $(this).change();
  1062. }
  1063. });
  1064. }
  1065. }
  1066. /**
  1067. * 处理图库系统
  1068. */
  1069. function image()
  1070. {
  1071. if($(".dever-note").length)
  1072. {
  1073. $(".dever-note").each(function()
  1074. {
  1075. var key = $(this).attr('key');
  1076. $(this).inlineattachment(
  1077. {
  1078. uploadUrl: config.upload + '.drag?key='+ key
  1079. });
  1080. });
  1081. }
  1082. if($(".image_upload").length)
  1083. {
  1084. $(".image_upload").each(function(i)
  1085. {
  1086. var parent = $(this).parent().parent();
  1087. //alert(parent.attr('id'));
  1088. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  1089. {
  1090. return;
  1091. }
  1092. loadUpload(i,$(this),$(this).attr('key'),config.upload + '.start', config.lib + 'upload/');//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  1093. })
  1094. }
  1095. }
  1096. /**
  1097. * 修改密码
  1098. */
  1099. function pass(e)
  1100. {
  1101. var html = '<style>.password_edit div{margin:10px;}.password_edit input{width:200px;}</style><div class="password_edit">';
  1102. html += '<div><span>旧密码:</span><input type="password" class="form-control form_margin" id="edit_old_password" /></div>';
  1103. html += '<div><span>新密码:</span><input type="password" class="form-control form_margin" id="edit_new_password" /></div>';
  1104. html += '</div>';
  1105. $('#dever_modal_body').html(html);
  1106. $('#dever_modal_title').html('修改密码');
  1107. $("#dever_modal_yes").unbind('click').bind('click', function()
  1108. {
  1109. var old_password = $("#edit_old_password").val();
  1110. var new_password = $("#edit_new_password").val();
  1111. if(!old_password || !new_password)
  1112. {
  1113. alert('请输入密码');
  1114. return;
  1115. }
  1116. if(old_password == new_password)
  1117. {
  1118. alert('旧密码和新密码相同');
  1119. return;
  1120. }
  1121. $.post(config.host + 'auth.password', {old:old_password,new:new_password}, function(t)
  1122. {
  1123. alert(t);
  1124. $("#dever_modal_no").click();
  1125. })
  1126. })
  1127. }
  1128. var MSG = [];
  1129. /**
  1130. * 打开弹窗
  1131. */
  1132. //function showMsg(title, e, id, func)
  1133. function showMsg(title, e, id, func)
  1134. {
  1135. if(id.indexOf('http://') == -1)
  1136. {
  1137. if($(id).length)
  1138. {
  1139. var html = $(id).html();
  1140. if($(id).html())
  1141. {
  1142. var html = $(id).html();
  1143. MSG[id] = html;
  1144. $(id).html('');
  1145. }
  1146. else
  1147. {
  1148. var html = MSG[id];
  1149. }
  1150. }
  1151. else
  1152. {
  1153. var html = id;
  1154. }
  1155. $('#dever_modal_body').html(html);
  1156. $('#dever_modal_title').html(title);
  1157. if(func)
  1158. {
  1159. $("#dever_modal_yes").unbind('click').bind('click', func);
  1160. }
  1161. }
  1162. else
  1163. {
  1164. if(e)
  1165. {
  1166. data = e.attr('msg-send');
  1167. }
  1168. $.getJSON(id+'?json=1',{data:data},function(t)
  1169. {
  1170. t = t.data;
  1171. $('#dever_modal_body').html(t);
  1172. $('#dever_modal_title').html(title);
  1173. if(func)
  1174. {
  1175. $("#dever_modal_yes").unbind('click').bind('click', func);
  1176. }
  1177. });
  1178. }
  1179. }
  1180. function updateMsg(id)
  1181. {
  1182. $("#"+id).submit();
  1183. }
  1184. function showAlert(msg, func, title)
  1185. {
  1186. if (!title) {
  1187. title = $("#dever-name").html() + '提醒您';
  1188. }
  1189. //$("#dever_modal_no").click();
  1190. $("#dever_modal").modal();
  1191. $('#dever_modal_body').html(msg);
  1192. $('#dever_modal_title').html(title);
  1193. if(func)
  1194. {
  1195. $("#dever_modal_yes").unbind('click').bind('click', func);
  1196. }
  1197. else
  1198. {
  1199. $("#dever_modal_yes").unbind('click').bind('click', function(){$("#dever_modal_no").click()});
  1200. }
  1201. }
  1202. /*
  1203. var test =
  1204. {
  1205. refreshPage: false,
  1206. addAjaxFlag: true,
  1207. //添加收藏
  1208. add: function(cfg)
  1209. {
  1210. }
  1211. }
  1212. */
  1213. function showToggle(e)
  1214. {
  1215. var id = e.attr('toggle');
  1216. var child = e.attr('toggle_child');
  1217. var parent = e.parent();
  1218. parent.parent().find('li').removeClass('active');
  1219. parent.addClass('active');
  1220. $(child).fadeOut(100);
  1221. $(id).fadeIn(500);
  1222. loadEditor($(id).find('.editor'));
  1223. }
  1224. function select_linkage(level, id, url, name, value, valid, w, total, search, level_param)
  1225. {
  1226. var e = '#' + id;
  1227. var parent = value.split(',');
  1228. var cur = parent[0];
  1229. parent.remove(cur);
  1230. value = parent.join(',');
  1231. var html = '';
  1232. var old = level;
  1233. if (!total) {
  1234. level_id = 0;
  1235. } else {
  1236. if (level >= total) {
  1237. //$(e).show();
  1238. return;
  1239. }
  1240. level_id = $(e + '_' + level).val();
  1241. level = parseInt(level) + 1;
  1242. }
  1243. $.getJSON(url + '?json=1', {level_search:search, level_id:level_id, level_num:level,level_param:level_param}, function(t) {
  1244. var check = '';
  1245. if (t.status == 1) {
  1246. var total = t.data.level_total;
  1247. var data = t.data.list;
  1248. if(!$(e + '_' + level).length) {
  1249. 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+'\');">';
  1250. }
  1251. for (a in data) {
  1252. if (data[a].value) {
  1253. check = '';
  1254. if (cur == data[a].value) {
  1255. check = ' selected';
  1256. }
  1257. html += '<option value="'+data[a].value+'" '+check+'>'+data[a].name+'</option>';
  1258. }
  1259. }
  1260. if(!$(e + '_' + level).length) {
  1261. html += '</select><span>&nbsp;&nbsp;</span>';
  1262. $(e).append(html);
  1263. $(e + '_' + level).change();
  1264. } else {
  1265. $(e + '_' + level).html(html);
  1266. $(e + '_' + level).change();
  1267. }
  1268. } else {
  1269. $(e + '_' + old).nextAll('select').remove();
  1270. $(e + '_' + old).next('span').nextAll('span').remove();
  1271. }
  1272. /*
  1273. if ($('#' + name + '_level_value').length) {
  1274. var total = $(id).find('select').length;
  1275. $('#' + name + '_level_value').val(total);
  1276. }
  1277. if ($('#' + name + '_up_value').length) {
  1278. $('#' + name + '_up_value').val($(id + '_-2').val());
  1279. }
  1280. */
  1281. });
  1282. }
  1283. /*
  1284. function select_mul(level, id, url, name, value, valid, w, num)
  1285. {
  1286. if(level == 0)
  1287. {
  1288. $(id).find('select').remove();
  1289. $(id).find('span').remove();
  1290. return;
  1291. }
  1292. var parent = value.split(',');
  1293. var cur = parent[0];
  1294. parent.remove(cur);
  1295. value = parent.join(',');
  1296. var html = '';
  1297. var old = level;
  1298. if(level != -1)
  1299. {
  1300. if($(id + '_' + level).length)
  1301. {
  1302. level = $(id + '_' + level).val();
  1303. }
  1304. alert(level);
  1305. if(level == 0)
  1306. {
  1307. $(id + '_' + old).nextAll('select').remove();
  1308. $(id + '_' + old).next('span').nextAll('span').remove();
  1309. if($('#' + name + '_level_value').length)
  1310. {
  1311. var total = $(id).find('select').length;
  1312. $('#' + name + '_level_value').val(total);
  1313. }
  1314. if(old == -2 && $('#' + name + '_value_value').length)
  1315. {
  1316. $('#' + name + '_value_value').val(level);
  1317. }
  1318. return;
  1319. }
  1320. if(old == -2)
  1321. {
  1322. $(id + '_' + old).nextAll('select').remove();
  1323. $(id + '_' + old).next('span').nextAll('span').remove();
  1324. }
  1325. if($('#' + name + '_value_value').length)
  1326. {
  1327. $('#' + name + '_value_value').val(level);
  1328. }
  1329. }
  1330. var total = $(id).find('select').length;
  1331. if(num > 0 && total >= num)
  1332. {
  1333. return;
  1334. }
  1335. var get = url.replace('{level}', level);
  1336. if(level == -1)
  1337. {
  1338. level = -2;
  1339. }
  1340. if(!$(id + '_' + level).length)
  1341. {
  1342. $.getJSON(get + '&json=1', {total:total,level:level}, function(t)
  1343. {
  1344. var check = '';
  1345. if(t.status == 1)
  1346. {
  1347. 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+');">';
  1348. console.log(t.data);
  1349. for(a in t.data)
  1350. {
  1351. if(t.data[a].value)
  1352. {
  1353. check = '';
  1354. if(cur == t.data[a].value)
  1355. {
  1356. check = ' selected';
  1357. }
  1358. html += '<option value="'+t.data[a].value+'" '+check+'>'+t.data[a].name+'</option>';
  1359. }
  1360. }
  1361. html += '</select><span>&nbsp;&nbsp;</span>';
  1362. $(id).append(html);
  1363. $(id + '_' + level).change();
  1364. }
  1365. else
  1366. {
  1367. $(id + '_' + old).nextAll('select').remove();
  1368. $(id + '_' + old).next('span').nextAll('span').remove();
  1369. }
  1370. if($('#' + name + '_level_value').length)
  1371. {
  1372. var total = $(id).find('select').length;
  1373. $('#' + name + '_level_value').val(total);
  1374. }
  1375. if($('#' + name + '_up_value').length)
  1376. {
  1377. $('#' + name + '_up_value').val($(id + '_-2').val());
  1378. }
  1379. });
  1380. }
  1381. }
  1382. */
  1383. //处理更新页面的一些功能,写到一起吧
  1384. var dever_update =
  1385. {
  1386. addIndex : 2,
  1387. index : [],
  1388. auto : false,
  1389. save_key : '',
  1390. init : function()
  1391. {
  1392. var self = this;
  1393. self.index = [];
  1394. // 增加整个更新的表单
  1395. if($(".dever_update_add").length)
  1396. {
  1397. $('.dever_update_add').unbind('click').bind('click', function()
  1398. {
  1399. self.add($(this));
  1400. })
  1401. }
  1402. /* 以后再增加 同时更新另外一个表
  1403. if($(".form-add-content").length)
  1404. {
  1405. var url = config.host + 'auth.password';
  1406. var url = 'http://localhost/dever/manage/?database.update?project=weixin&table=message&menu=weixin&menu_id=39&ajax=1';
  1407. $.get(url, function(t)
  1408. {
  1409. $(".form-add-content").html(t);
  1410. init();
  1411. })
  1412. }
  1413. */
  1414. //增加某一部分表单
  1415. if($(".dever_form_add").length)
  1416. {
  1417. $('.dever_form_add').each(function()
  1418. {
  1419. var key = $.attr('toggle_key');
  1420. if(typeof(self.index[key]) == "undefined")
  1421. {
  1422. self.index[key] = 0;
  1423. }
  1424. $(this).unbind('click').bind('click', function()
  1425. {
  1426. self.append($(this));
  1427. })
  1428. })
  1429. self.del();
  1430. }
  1431. // 开启自动保存
  1432. if($("#struct").length)
  1433. {
  1434. var save = $("#struct").attr('save');
  1435. if(save == 'yes')
  1436. {
  1437. //检测
  1438. self.save_key = location.href + 'test';
  1439. self.check();
  1440. }
  1441. }
  1442. if($('.dever-note').length)
  1443. {
  1444. $('.dever-note').each(function()
  1445. {
  1446. var mditor = new Mditor($(this),{
  1447. fixedHeight:true
  1448. });
  1449. mditor.openPreview();
  1450. })
  1451. }
  1452. },
  1453. save : function()
  1454. {
  1455. //var data = $("#data-1").html();
  1456. var data = [];
  1457. $(".update_value").each(function(i)
  1458. {
  1459. if($(this).attr("update_type") == 'checked')
  1460. {
  1461. data[i] = $(this).get(0).checked;
  1462. }
  1463. else if($(this).attr("update_type") == 'html')
  1464. {
  1465. data[i] = $(this).html();
  1466. }
  1467. else if($(this).attr("update_type") == 'src')
  1468. {
  1469. data[i] = $(this).attr('src');
  1470. }
  1471. else
  1472. {
  1473. data[i] = $(this).val();
  1474. }
  1475. });
  1476. store.set(this.save_key, data.join('|||'));
  1477. //console.info(data);
  1478. },
  1479. recover : function()
  1480. {
  1481. if(confirm('确定恢复上次保存的数据吗?'))
  1482. {
  1483. var data = store.get(this.save_key).split('|||');
  1484. if(data)
  1485. {
  1486. var value = $(".update_value");
  1487. for(var k in data)
  1488. {
  1489. var e = value.eq(k);
  1490. if(e.attr('update_type') == 'checked')
  1491. {
  1492. if(data[k] == 'true')
  1493. {
  1494. e.get(0).checked = true;
  1495. }
  1496. else
  1497. {
  1498. e.get(0).checked = false;
  1499. }
  1500. }
  1501. else if(e.attr('update_type') == 'html')
  1502. {
  1503. e.html(data[k]);
  1504. }
  1505. else if(e.attr('update_type') == 'src')
  1506. {
  1507. e.attr('src', data[k]);
  1508. }
  1509. else
  1510. {
  1511. if(e.attr('id'))
  1512. {
  1513. var id = e.attr('id');
  1514. if(typeof(editors[id]) != "undefined")
  1515. {
  1516. editors[id].setContent(data[k]);
  1517. }
  1518. }
  1519. e.val(data[k]);
  1520. }
  1521. }
  1522. store.set(this.save_key, '');
  1523. this.check();
  1524. }
  1525. }
  1526. },
  1527. check : function()
  1528. {
  1529. var data = store.get(this.save_key);
  1530. var self = this;
  1531. if(data)
  1532. {
  1533. $(".dever_save").unbind('click').bind('click', function()
  1534. {
  1535. self.recover();
  1536. }).show();
  1537. }
  1538. else
  1539. {
  1540. $(".dever_save").hide();
  1541. self.auto = setInterval(function(){self.save()}, 3000);
  1542. }
  1543. },
  1544. del : function()
  1545. {
  1546. var self = this;
  1547. if($(".dever_form_delete").length)
  1548. {
  1549. $('.dever_form_delete').each(function()
  1550. {
  1551. $(this).unbind('click').bind('click', function()
  1552. {
  1553. var parent = $(this).parent();
  1554. var id = parent.attr('id');
  1555. var index = parseInt($('#tab-' + id).attr('toggle_id'));
  1556. var key = $('#tab-' + id).attr('toggle_key');
  1557. if(index <= 1 && self.index[key] <= index)
  1558. {
  1559. }
  1560. else if(index <= 1 && self.index[key] > index)
  1561. {
  1562. index = index+1;
  1563. $("#tab-"+key+"-child-" + index).click();
  1564. }
  1565. else
  1566. {
  1567. index = index-1;
  1568. $("#tab-"+key+"-child-" + index).click();
  1569. };
  1570. $('#tab-' + id).parent().remove();
  1571. parent.remove();
  1572. self.index[key]--;
  1573. })
  1574. })
  1575. }
  1576. },
  1577. append : function(e)
  1578. {
  1579. var self = this;
  1580. var key = e.attr('toggle_key');
  1581. var child = '.dever_'+key+'_child';
  1582. if(typeof(self.index[key]) == "undefined")
  1583. {
  1584. self.index[key] = 0;
  1585. }
  1586. if(self.index[key] <= 0)
  1587. {
  1588. self.index[key] = $(child).length;
  1589. }
  1590. if(self.index[key] > 30)
  1591. {
  1592. alert('最多只能增加30条');
  1593. return;
  1594. }
  1595. var p = e.parent();
  1596. var id = key + '-child-' + self.index[key];
  1597. var name = '第' + (self.index[key]) + '条';
  1598. 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>');
  1599. var e = e.parent().parent();
  1600. var n = e.next();
  1601. var p = e.parent();
  1602. var content = n.html();
  1603. content = content.replaceAll('_c_', '_c_' + (self.index[key]-1) + '_i_');
  1604. content = '<div id="'+id+'" style="display:none;" class="'+n.attr('class')+' dever_form_add_child">' + content + '</div>';
  1605. p.append(content);
  1606. $('#update_' + key +'_c_' + (self.index[key]-1) + '_i_' + 'order_value').val(parseInt($('#update_' + key +'_c_' + (self.index[key]-2) + '_i_' + 'order_value').val())+1);
  1607. self.del();
  1608. //$("html,body").animate({scrollTop:$('.dever_form_add_child').eq(this.appendIndex).offset().top},500);
  1609. self.index[key]++;
  1610. image();
  1611. loadShow();
  1612. autocomplete();
  1613. change();
  1614. },
  1615. add : function(e)
  1616. {
  1617. var self = this;
  1618. var p = e.parent();
  1619. var id = 'data-' + this.addIndex;
  1620. var name = '新增数据-' + (this.addIndex-1);
  1621. p.before('<li><a href="#'+id+'" data-toggle="tab">'+name+'</a></li>');
  1622. var content = $("#myTabContent").find('.tab-pane').eq(0).html();
  1623. content = content.replaceAll('update_', 'update_' + this.addIndex + '__');
  1624. content = '<div class="tab-pane fade" id="'+id+'">' + content + '</div>';
  1625. $("#myTabContent").append(content);
  1626. $('#update_' + this.addIndex + '__where_id').val('-1');
  1627. this.addIndex++;
  1628. }
  1629. }
  1630. String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) {
  1631. if (!RegExp.prototype.isPrototypeOf(reallyDo)) {
  1632. return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi": "g")), replaceWith);
  1633. } else {
  1634. return this.replace(reallyDo, replaceWith);
  1635. }
  1636. }
  1637. Array.prototype.remove = function(val) {
  1638. var index = -1;
  1639. for(var i = 0; i < this.length; i++)
  1640. {
  1641. if(this[i] == val)
  1642. {
  1643. index = i;
  1644. }
  1645. }
  1646. if (index > -1) {
  1647. this.splice(index, 1);
  1648. }
  1649. };
  1650. $.fn.pasteEvents = function( delay ) {
  1651. if (delay == undefined) delay = 20;
  1652. return $(this).each(function() {
  1653. var $el = $(this);
  1654. $el.on("paste", function() {
  1655. $el.trigger("prepaste");
  1656. setTimeout(function() { $el.trigger("postpaste"); }, delay);
  1657. });
  1658. });
  1659. };
  1660. $("textarea").on("postpaste", function()
  1661. {
  1662. if($(this).val().indexOf('<') != -1)
  1663. {
  1664. $(this).val(toMarkdown($(this).val()));
  1665. }
  1666. }).pasteEvents();