main.js 35 KB

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