main.js 36 KB

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