main.js 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967
  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'), 'input');
  373. }
  374. })
  375. $(".show_input select").each(function()
  376. {
  377. if($(this).find('option:selected').text())
  378. {
  379. inputShow($(this), $(this).attr('show_id'));
  380. }
  381. })
  382. }
  383. }
  384. function inputShow(e,n,t)
  385. {
  386. $(".show_" + n).hide();
  387. var array = ['input', 'textarea'];
  388. for(var a in array)
  389. {
  390. if ($(".show_" + n).find(array[a]).length) {
  391. var c = $(".show_" + n).find(array[a]).attr('class');
  392. if (c.indexOf('validate[required]') > -1) {
  393. $(".show_" + n).find(array[a]).removeClass('validate[required]').addClass('validates');
  394. }
  395. }
  396. }
  397. if (t == 'input') {
  398. var item = e.parent().find('input');
  399. item.each(function()
  400. {
  401. if($(this).get(0).checked == true)
  402. {
  403. inputShowOne($(this),n);
  404. }
  405. });
  406. } else {
  407. var item = e.parent().find('select');
  408. item.each(function()
  409. {
  410. if($(this).find('option:selected').text())
  411. {
  412. inputShowOne($(this),n);
  413. }
  414. });
  415. }
  416. }
  417. function inputShowOne(e,n)
  418. {
  419. var value = e.val();
  420. var ele = '.show_' + n + '_ajax';
  421. if ($(ele).length) {
  422. $(ele).each(function()
  423. {
  424. var self = $(this);
  425. var url = self.attr('dever-ajax');
  426. $.getJSON(url + value + '&callback=?', function(t) {
  427. self.find('.margin-top').html(t.data);
  428. inputShowOneValiDate(self);
  429. checkbox();
  430. })
  431. })
  432. } else {
  433. ele = '.show_' + n + '_' + value;
  434. inputShowOneValiDate($(ele));
  435. }
  436. }
  437. function inputShowOneValiDate(e)
  438. {
  439. e.show();
  440. var array = ['input', 'textarea'];
  441. for(var a in array)
  442. {
  443. if(e.length && e.attr('class').indexOf('show_no') == -1)
  444. {
  445. e.find(array[a]).each(function()
  446. {
  447. var parent = $(this).parent();
  448. if($(this).attr('class') != 'editor' && $(this).attr('class').indexOf('validates') > -1 && parent.find('label').length && parent.find('label').html().indexOf('选填') == -1)
  449. {
  450. $(this).addClass('validate[required]');
  451. }
  452. })
  453. }
  454. }
  455. }
  456. //批量更新
  457. function list_mul(e)
  458. {
  459. var type = parseInt($("#mul_type").val());
  460. if(type != 1 && type != 2)
  461. {
  462. alert('您还没有选择数据更新方式');
  463. return;
  464. }
  465. if(confirm('确定进行此项操作吗?'))
  466. {
  467. //e.html('更新中').unbind('click');
  468. $('#method').val('mul');
  469. $('#function').val('msg');
  470. $('#form1').attr('target', 'f1').submit();
  471. }
  472. }
  473. //搜索
  474. function list_search(e)
  475. {
  476. $('#method').val('search');
  477. $('#function').val('');
  478. $('#form1').attr('target', '').submit();
  479. }
  480. //更新数据
  481. function update(e, id, project, table, notice)
  482. {
  483. var call = function()
  484. {
  485. var col = e.attr('name').replace('up_col_', '');
  486. var value = e.val();
  487. var url = config.host + 'database.update_action?json=1';
  488. $.post(url, {where_id:id,col:col,value:value,project:project,table:table}, function(t)
  489. {
  490. notify('操作已成功!您的操作已修改当前选项!');
  491. preview();
  492. })
  493. }
  494. if(notice && confirm(notice))
  495. {
  496. call();
  497. }
  498. else
  499. {
  500. call();
  501. }
  502. }
  503. function notify(msg)
  504. {
  505. var notice = new PNotify({
  506. title: '提示信息',
  507. text: msg,
  508. buttons: {
  509. closer: false,
  510. sticker: false
  511. }
  512. });
  513. notice.get().click(function() {
  514. notice.remove();
  515. });
  516. }
  517. //模板选择
  518. function template()
  519. {
  520. if(config.template)
  521. {
  522. $('body').attr('class', 'theme-' + config.template);
  523. }
  524. if($(".selector").length)
  525. {
  526. $(".selector").each(function()
  527. {
  528. if($(this).data('check') == 'checked')
  529. {
  530. selector($(this));
  531. }
  532. })
  533. }
  534. }
  535. //选择器
  536. function selector(e)
  537. {
  538. var value = e.data('value');
  539. var name = e.data('name');
  540. $('#'+name+'_value').val(value);
  541. $('.'+name+'_selector').children().css({'border':'1px solid #ccc'});
  542. e.children().css({'border':'1px solid black'});
  543. if(name == 'update_template')
  544. {
  545. $('body').attr('class', 'theme-' + value);
  546. }
  547. }
  548. //根据e的值,来载入其他数据
  549. function loading(e, data)
  550. {
  551. var value = e.val();
  552. if(e.attr('id') && e.attr('id').indexOf('_temp') != -1)
  553. {
  554. var id = e.attr('id').replace('_temp', '');
  555. if($('#' + id).length)
  556. {
  557. var value = $('#' + id).val();
  558. }
  559. }
  560. if(data.element)
  561. {
  562. if(data.url)
  563. {
  564. data.value = value;
  565. $.getJSON(data.url, data, function(t)
  566. {
  567. $('#update_'+data.element+'_value').val(t.data);
  568. });
  569. }
  570. else
  571. {
  572. $('#update_'+data.element+'_value').val(value);
  573. }
  574. }
  575. else if(data.url)
  576. {
  577. data.value = value;
  578. data.where_id = $('#update_where_id').val();
  579. data.table = $('#table').val();
  580. data.project = $('#project').val();
  581. $.getJSON(data.url, data, function(s)
  582. {
  583. t = s.data;
  584. if(t.indexOf('onblur') != -1)
  585. {
  586. eval(t);
  587. }
  588. else
  589. {
  590. var parent = e.parent().parent();
  591. if(t.indexOf('status') == -1)
  592. {
  593. if(data.type == 1)
  594. {
  595. $('.checking_1,.checking_2,.checking_3,.checking_4').each(function()
  596. {
  597. $(this).remove();
  598. });
  599. }
  600. else
  601. {
  602. $('.checking_-1,.checking_3,.checking_4').each(function()
  603. {
  604. $(this).remove();
  605. });
  606. }
  607. parent.after(t);
  608. checkbox();
  609. }
  610. }
  611. });
  612. }
  613. }
  614. //根据e的值,来载入其他数据,先检测是否选中
  615. function checking(name, e, data)
  616. {
  617. var value = [];
  618. $('.' + name).each(function()
  619. {
  620. if($(this).get(0).checked == true)
  621. {
  622. value.push($(this).val());
  623. }
  624. });
  625. if(data.url)
  626. {
  627. data.value = value.join(',');
  628. data.where_id = $('#update_where_id').val();
  629. data.table = $('#table').val();
  630. data.project = $('#project').val();
  631. if(data.check)
  632. {
  633. data.check_value = false;
  634. $(data.check).each(function()
  635. {
  636. if($(this).get(0).checked == true)
  637. {
  638. data.check_value = $(this).val();
  639. }
  640. });
  641. }
  642. $.getJSON(data.url, data, function(s)
  643. {
  644. t = s.data;
  645. var parent = e.parent().parent().parent();
  646. if(t.indexOf('status') == -1)
  647. {
  648. if(data.type == 1)
  649. {
  650. $('.checking_1,.checking_2,.checking_3,.checking_4').each(function()
  651. {
  652. $(this).remove();
  653. });
  654. }
  655. else
  656. {
  657. $('.checking_-1,.checking_3,.checking_4').each(function()
  658. {
  659. $(this).remove();
  660. });
  661. }
  662. parent.after(t);
  663. checkbox();
  664. }
  665. });
  666. }
  667. }
  668. function autocomplete()
  669. {
  670. if ($("input").length) {
  671. $("input").each(function()
  672. {
  673. $(this).attr('autocomplete', 'new-password');
  674. });
  675. }
  676. if($("input[complete]").length)
  677. {
  678. $("input[complete]").each(function()
  679. {
  680. var cache = {};
  681. var self = $(this);
  682. self.autocomplete(
  683. {
  684. minLength: 2,
  685. source: function( request, response )
  686. {
  687. var term = request.term;
  688. if ( term in cache ) {
  689. response( cache[ term ] );
  690. return;
  691. }
  692. var cate = self.attr('complete_cate');
  693. if (cate) {
  694. request[cate] = $('update_' + cate + '_value').val();
  695. }
  696. $.getJSON(self.attr('complete') + '&callback=?', request, function( data, status, xhr ) {
  697. data = data.data
  698. cache[ term ] = data;
  699. var state = true;
  700. for(var i in data)
  701. {
  702. if(data[i].id <=0)
  703. {
  704. state = false;
  705. }
  706. }
  707. if(state)
  708. {
  709. response( data );
  710. }
  711. });
  712. },
  713. select: function( event, ui )
  714. {
  715. //log( "Selected: " + ui.item.value + " aka " + ui.item.id );
  716. var value = self.attr('complete_callback');
  717. var id = self.attr('id').replace('_temp', '');
  718. $("#" + id).val(ui.item[value]);
  719. }
  720. });
  721. })
  722. }
  723. }
  724. //后台通用的提示
  725. function msg(value)
  726. {
  727. $("#dever_modal_no").click();
  728. if(!value.data)
  729. {
  730. value.data = value.msg;
  731. }
  732. if(value == 1)
  733. {
  734. location.reload();
  735. return;
  736. }
  737. submit();
  738. var url = '';
  739. if(value.data != 'reload' && value.status == 2)
  740. {
  741. showAlert(value.msg, false, '错误提示');
  742. //alert(value.data);
  743. //location.reload();
  744. return;
  745. }
  746. else if(value.data == 'reload')
  747. {
  748. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  749. {
  750. pjax({url: location.href, container: config.layout})
  751. }
  752. else
  753. {
  754. location.reload();
  755. }
  756. return;
  757. }
  758. else
  759. {
  760. if(value.data.indexOf('http://') != -1)
  761. {
  762. url = value.data;
  763. }
  764. else if($("#url").length)
  765. {
  766. url = $("#url").val();
  767. }
  768. else
  769. {
  770. notify(value.data)
  771. return;
  772. }
  773. if(url)
  774. {
  775. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  776. {
  777. pjax({url: url, container: config.layout});
  778. }
  779. else
  780. {
  781. location.href = url;
  782. }
  783. }
  784. else
  785. {
  786. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  787. {
  788. pjax({url: location.href, container: config.layout});
  789. }
  790. else
  791. {
  792. location.reload();
  793. }
  794. }
  795. }
  796. return;
  797. }
  798. /**
  799. * 处理多选问题,处理全选按钮
  800. */
  801. function checkbox()
  802. {
  803. if($(".autoload").length)
  804. {
  805. $(".autoload").each(function()
  806. {
  807. if($(this).get(0).checked == true)
  808. {
  809. $(this).removeClass('autoload');
  810. $(this).load();
  811. }
  812. });
  813. }
  814. if($(".autoload_text").length)
  815. {
  816. $(".autoload_text").each(function()
  817. {
  818. if($(this).val())
  819. {
  820. $(this).removeClass('autoload_text');
  821. $(this).load();
  822. }
  823. });
  824. }
  825. var name = 'checkbox-checkall';
  826. var checkbox = $("." + name);
  827. if(checkbox.length)
  828. {
  829. checkbox.click(function()
  830. {
  831. var self = $(this);
  832. $("." + name + "-" + self.val()).each(function()
  833. {
  834. $(this).get(0).checked = self.get(0).checked;
  835. var next = $(this).next();
  836. if($(this).get(0).checked == true)
  837. {
  838. if(next.length && next.attr('type') != 'checkbox')
  839. {
  840. next.attr('disabled', false);
  841. }
  842. if($("#mul_type").length)
  843. {
  844. $("#mul_type").val(1);
  845. }
  846. }
  847. else
  848. {
  849. if(next.length && next.attr('type') != 'checkbox')
  850. {
  851. next.attr('disabled', true);
  852. }
  853. if($("#mul_type").length)
  854. {
  855. $("#mul_type").val(0);
  856. }
  857. }
  858. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
  859. inputShow($(this), 'col');
  860. }
  861. })
  862. });
  863. checkbox.each(function()
  864. {
  865. var self = $(this);
  866. $("." + name + "-" + self.val()).each(function()
  867. {
  868. $(this).click(function()
  869. {
  870. var next = $(this).next();
  871. if($(this).get(0).checked == true)
  872. {
  873. self.get(0).checked = true;
  874. if(self.attr('type') == 'radio')
  875. {
  876. //如果父选项是radio类型,做下限制
  877. //alert(1);
  878. }
  879. if($("#mul_type").length)
  880. {
  881. $("#mul_type").val(1);
  882. }
  883. if(next.length && next.attr('type') != 'checkbox')
  884. {
  885. next.attr('disabled', false);
  886. }
  887. }
  888. else
  889. {
  890. //子选项取消时,处理一下父级选项
  891. var num = 0;
  892. $("." + name + "-" + self.val()).each(function()
  893. {
  894. if($(this).get(0).checked == true)
  895. {
  896. num = 1;
  897. }
  898. });
  899. if(num == 0)
  900. {
  901. self.get(0).checked = false;
  902. if($("#mul_type").length)
  903. {
  904. $("#mul_type").val(0);
  905. }
  906. }
  907. if(next.length && next.attr('type') != 'checkbox')
  908. {
  909. next.attr('disabled', true);
  910. }
  911. }
  912. })
  913. if($(this).get(0).checked == true)
  914. {
  915. self.get(0).checked = true;
  916. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
  917. inputShow($(this), 'col');
  918. }
  919. }
  920. });
  921. })
  922. }
  923. }
  924. /**
  925. * 处理双击编辑
  926. */
  927. function edit()
  928. {
  929. if($(".edit").length)
  930. {
  931. $(".edit").each(function()
  932. {
  933. $(this).bind('dblclick', function()
  934. {
  935. var col = $(this).attr('data-col');
  936. var project = $(this).attr('data-project');
  937. var table = $(this).attr('data-table');
  938. var url = $(this).attr('data-url');
  939. var id = $(this).attr('data-id');
  940. var html = $(this).attr('data-content');
  941. var type = $(this).attr('data-type');
  942. if($(this).find(".edit-content").length)
  943. {
  944. html = $(this).find(".edit-content").html();
  945. html = html.replace('<!--', '<');
  946. html = html.replace('-->', '>');
  947. }
  948. if(html.indexOf('input') == -1)
  949. {
  950. if(type && type == 'textarea')
  951. {
  952. $(this).html('<textarea type="text" name="edit" id="edit" rows="10" cols="60">'+html+'</textarea>');
  953. }
  954. else
  955. {
  956. $(this).html('<input type="text" name="edit" id="edit" value="'+html+'">');
  957. }
  958. var self = $(this);
  959. self.find("#edit").blur(function()
  960. {
  961. var value = self.find("#edit").val();
  962. if(!value)
  963. {
  964. alert('不能为空');
  965. return;
  966. }
  967. if($(this).find(".edit-content").length)
  968. {
  969. $(this).find(".edit-content").html(value);
  970. }
  971. else
  972. {
  973. self.attr('data-content', value);
  974. }
  975. self.html(value);
  976. $.post(url, {project:project,table:table,value:value,where_id:id,col:col}, function(t)
  977. {
  978. notify('修改成功');
  979. preview();
  980. /*
  981. if(type && type == 'textarea')
  982. {
  983. self.html(t);
  984. }
  985. */
  986. })
  987. })
  988. }
  989. });
  990. })
  991. }
  992. }
  993. function preview()
  994. {
  995. if($("#preview").length)
  996. {
  997. var time = Date.parse(new Date());
  998. var src = $('#preview').attr('src').split('#');
  999. $('#preview').attr('src', src[0] + '&' + time + '#' + src[1]);
  1000. }
  1001. }
  1002. function del()
  1003. {
  1004. if($(".oper_delete").length)
  1005. {
  1006. $(".oper_delete").each(function()
  1007. {
  1008. var href = $(this).attr('href');
  1009. $(this).attr('href', '#');
  1010. $(this).unbind('click');
  1011. $(this).bind('click', function()
  1012. {
  1013. del_act(href);
  1014. });
  1015. })
  1016. }
  1017. }
  1018. /**
  1019. * 处理删除
  1020. */
  1021. function del_act(href)
  1022. {
  1023. if(confirm('确定进行此项操作吗?'))
  1024. {
  1025. $.getJSON(href + '&json=1&callback=?', {}, function(t)
  1026. {
  1027. msg(t);
  1028. })
  1029. }
  1030. }
  1031. /**
  1032. * 处理特殊加载的按钮
  1033. */
  1034. function load(href)
  1035. {
  1036. if(confirm('确定进行此项操作吗?'))
  1037. {
  1038. if(href.indexOf('&') == -1)
  1039. {
  1040. href += '?json=1&callback=?';
  1041. }
  1042. else
  1043. {
  1044. href += '&json=1&callback=?';
  1045. }
  1046. $.getJSON(href, {}, function(t)
  1047. {
  1048. msg(t);
  1049. //location.reload();
  1050. })
  1051. }
  1052. /*
  1053. showAlert('确定进行此项操作吗?', function()
  1054. {
  1055. $("#dever_modal_no").click();
  1056. $.getJSON(href + '&json=1', {}, function(t)
  1057. {
  1058. msg(t);
  1059. })
  1060. });
  1061. */
  1062. }
  1063. /**
  1064. * 处理特殊加载的按钮
  1065. */
  1066. function jump(href, form)
  1067. {
  1068. if (form) {
  1069. var param = formData(form);
  1070. href += param[1];
  1071. }
  1072. location.href = href;
  1073. }
  1074. /**
  1075. * 处理change
  1076. */
  1077. function change()
  1078. {
  1079. if($(".change").length)
  1080. {
  1081. $(".change").each(function()
  1082. {
  1083. var key = $(this).attr('data-child');
  1084. /*
  1085. $('.' + key).each(function()
  1086. {
  1087. if($(this).find('select option:selected').val())
  1088. {
  1089. $(this).show();
  1090. $('#set_cate_id_child').get(0).value = $(this).attr('parent');
  1091. }
  1092. });
  1093. */
  1094. $(this).change(function()
  1095. {
  1096. $('.' + key).hide();
  1097. var v = $('.' + key + '_' + $(this).val());
  1098. var s = v.find('select');
  1099. s.change(function()
  1100. {
  1101. $('.' + key + '_value').val($(this).val());
  1102. })
  1103. if(v.length)
  1104. {
  1105. $('.' + key + '_value').val(s.val());
  1106. v.show();
  1107. }
  1108. else
  1109. {
  1110. $('.' + key + '_value').val(-1);
  1111. }
  1112. });
  1113. if($(this).val() > 0)
  1114. {
  1115. $(this).change();
  1116. }
  1117. });
  1118. }
  1119. }
  1120. /**
  1121. * 处理图库系统
  1122. */
  1123. function image()
  1124. {
  1125. if($(".dever-note").length)
  1126. {
  1127. $(".dever-note").each(function()
  1128. {
  1129. var key = $(this).attr('key');
  1130. $(this).inlineattachment(
  1131. {
  1132. uploadUrl: config.upload + '.drag?key='+ key
  1133. });
  1134. });
  1135. }
  1136. if($(".image_upload").length)
  1137. {
  1138. $(".image_upload").each(function(i)
  1139. {
  1140. var parent = $(this).parent().parent();
  1141. //alert(parent.attr('id'));
  1142. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  1143. {
  1144. return;
  1145. }
  1146. loadUpload(i,$(this),$(this).attr('key'),config.upload + '.start', config.lib + 'upload/');//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  1147. })
  1148. }
  1149. }
  1150. /**
  1151. * 修改密码
  1152. */
  1153. function pass(e)
  1154. {
  1155. var html = '<style>.password_edit div{margin:10px;}.password_edit input{width:200px;}</style><div class="password_edit">';
  1156. html += '<div><span>旧密码:</span><input type="password" class="form-control form_margin" id="edit_old_password" /></div>';
  1157. html += '<div><span>新密码:</span><input type="password" class="form-control form_margin" id="edit_new_password" /></div>';
  1158. html += '</div>';
  1159. $('#dever_modal_body').html(html);
  1160. $('#dever_modal_title').html('修改密码');
  1161. $("#dever_modal_yes").unbind('click').bind('click', function()
  1162. {
  1163. var old_password = $("#edit_old_password").val();
  1164. var new_password = $("#edit_new_password").val();
  1165. if(!old_password || !new_password)
  1166. {
  1167. alert('请输入密码');
  1168. return;
  1169. }
  1170. if(old_password == new_password)
  1171. {
  1172. alert('旧密码和新密码相同');
  1173. return;
  1174. }
  1175. $.post(config.host + 'auth.password', {old:old_password,new:new_password}, function(t)
  1176. {
  1177. alert(t);
  1178. $("#dever_modal_no").click();
  1179. })
  1180. })
  1181. }
  1182. var MSG = [];
  1183. /**
  1184. * 打开弹窗
  1185. */
  1186. //function showMsg(title, e, id, func)
  1187. function showMsg(title, e, id, func, param)
  1188. {
  1189. if(id.indexOf('http://') == -1)
  1190. {
  1191. if($(id).length)
  1192. {
  1193. var html = $(id).html();
  1194. if($(id).html())
  1195. {
  1196. var html = $(id).html();
  1197. MSG[id] = html;
  1198. $(id).html('');
  1199. }
  1200. else
  1201. {
  1202. var html = MSG[id];
  1203. }
  1204. }
  1205. else
  1206. {
  1207. var html = id;
  1208. }
  1209. $('#dever_modal_body').html(html);
  1210. $('#dever_modal_title').html(title);
  1211. if (func) {
  1212. $("#dever_modal_yes").unbind('click').bind('click', func);
  1213. } else {
  1214. $("#dever_modal_yes").unbind('click').bind('click', function(){$("#dever_modal_no").click()});
  1215. }
  1216. }
  1217. else
  1218. {
  1219. var url = id;
  1220. var send = {};
  1221. if (param) {
  1222. send = param;
  1223. }
  1224. if (e && e.attr('msg-send')) {
  1225. send.data = e.attr('msg-send');
  1226. }
  1227. if (url.indexOf('?') != -1) {
  1228. url = url + '&';
  1229. } else {
  1230. url = url + '?';
  1231. }
  1232. $.getJSON(url+'json=1',send,function(t)
  1233. {
  1234. t = t.data;
  1235. $('#dever_modal_body').html(t);
  1236. $('#dever_modal_title').html(title);
  1237. if(func)
  1238. {
  1239. $("#dever_modal_yes").unbind('click').bind('click', func);
  1240. }
  1241. });
  1242. }
  1243. }
  1244. function updateMsg(id)
  1245. {
  1246. $("#"+id).submit();
  1247. }
  1248. function showAlert(msg, func, title)
  1249. {
  1250. if (!title) {
  1251. title = $("#dever-name").html() + '提醒您';
  1252. }
  1253. //$("#dever_modal_no").click();
  1254. $("#dever_modal").modal();
  1255. $('#dever_modal_body').html(msg);
  1256. $('#dever_modal_title').html(title);
  1257. if(func)
  1258. {
  1259. $("#dever_modal_yes").unbind('click').bind('click', func);
  1260. }
  1261. else
  1262. {
  1263. $("#dever_modal_yes").unbind('click').bind('click', function(){$("#dever_modal_no").click()});
  1264. }
  1265. }
  1266. function fastEdit(e, url, title, col)
  1267. {
  1268. var func = function()
  1269. {
  1270. submit_action();
  1271. };
  1272. var send = {};
  1273. send.col = col;
  1274. $.get(url,send,function(t)
  1275. {
  1276. var html = $(t).find('form').prop("outerHTML");
  1277. var valid = $(t).find('#valid').prop("outerHTML");
  1278. html = html + valid;
  1279. showAlert(html, func, title);
  1280. $('#update_button').hide();
  1281. init();
  1282. });
  1283. }
  1284. /*
  1285. var test =
  1286. {
  1287. refreshPage: false,
  1288. addAjaxFlag: true,
  1289. //添加收藏
  1290. add: function(cfg)
  1291. {
  1292. }
  1293. }
  1294. */
  1295. function showToggle(e)
  1296. {
  1297. var id = e.attr('toggle');
  1298. var child = e.attr('toggle_child');
  1299. var parent = e.parent();
  1300. parent.parent().find('li').removeClass('active');
  1301. parent.addClass('active');
  1302. $(child).fadeOut(100);
  1303. $(id).fadeIn(500);
  1304. loadEditor($(id).find('.editor'));
  1305. }
  1306. function select_linkage(level, id, url, name, value, valid, w, total, search, level_param)
  1307. {
  1308. var e = '#' + id;
  1309. var parent = value.split(',');
  1310. var cur = parent[0];
  1311. parent.remove(cur);
  1312. value = parent.join(',');
  1313. var html = '';
  1314. var old = level;
  1315. if (!total) {
  1316. level_id = 0;
  1317. } else {
  1318. if (level >= total) {
  1319. //$(e).show();
  1320. return;
  1321. }
  1322. level_id = $(e + '_' + level).val();
  1323. level = parseInt(level) + 1;
  1324. }
  1325. $.getJSON(url + '?json=1', {level_search:search, level_id:level_id, level_num:level,level_param:level_param}, function(t) {
  1326. var check = '';
  1327. if (t.status == 1) {
  1328. var total = t.data.level_total;
  1329. var data = t.data.list;
  1330. if(!$(e + '_' + level).length) {
  1331. 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+'\');">';
  1332. }
  1333. for (a in data) {
  1334. if (data[a].value) {
  1335. check = '';
  1336. if (cur == data[a].value) {
  1337. check = ' selected';
  1338. }
  1339. html += '<option value="'+data[a].value+'" '+check+'>'+data[a].name+'</option>';
  1340. }
  1341. }
  1342. if(!$(e + '_' + level).length) {
  1343. html += '</select><span>&nbsp;&nbsp;</span>';
  1344. $(e).append(html);
  1345. $(e + '_' + level).change();
  1346. } else {
  1347. $(e + '_' + level).html(html);
  1348. $(e + '_' + level).change();
  1349. }
  1350. } else {
  1351. $(e + '_' + old).nextAll('select').remove();
  1352. $(e + '_' + old).next('span').nextAll('span').remove();
  1353. }
  1354. /*
  1355. if ($('#' + name + '_level_value').length) {
  1356. var total = $(id).find('select').length;
  1357. $('#' + name + '_level_value').val(total);
  1358. }
  1359. if ($('#' + name + '_up_value').length) {
  1360. $('#' + name + '_up_value').val($(id + '_-2').val());
  1361. }
  1362. */
  1363. });
  1364. }
  1365. /*
  1366. function select_mul(level, id, url, name, value, valid, w, num)
  1367. {
  1368. if(level == 0)
  1369. {
  1370. $(id).find('select').remove();
  1371. $(id).find('span').remove();
  1372. return;
  1373. }
  1374. var parent = value.split(',');
  1375. var cur = parent[0];
  1376. parent.remove(cur);
  1377. value = parent.join(',');
  1378. var html = '';
  1379. var old = level;
  1380. if(level != -1)
  1381. {
  1382. if($(id + '_' + level).length)
  1383. {
  1384. level = $(id + '_' + level).val();
  1385. }
  1386. alert(level);
  1387. if(level == 0)
  1388. {
  1389. $(id + '_' + old).nextAll('select').remove();
  1390. $(id + '_' + old).next('span').nextAll('span').remove();
  1391. if($('#' + name + '_level_value').length)
  1392. {
  1393. var total = $(id).find('select').length;
  1394. $('#' + name + '_level_value').val(total);
  1395. }
  1396. if(old == -2 && $('#' + name + '_value_value').length)
  1397. {
  1398. $('#' + name + '_value_value').val(level);
  1399. }
  1400. return;
  1401. }
  1402. if(old == -2)
  1403. {
  1404. $(id + '_' + old).nextAll('select').remove();
  1405. $(id + '_' + old).next('span').nextAll('span').remove();
  1406. }
  1407. if($('#' + name + '_value_value').length)
  1408. {
  1409. $('#' + name + '_value_value').val(level);
  1410. }
  1411. }
  1412. var total = $(id).find('select').length;
  1413. if(num > 0 && total >= num)
  1414. {
  1415. return;
  1416. }
  1417. var get = url.replace('{level}', level);
  1418. if(level == -1)
  1419. {
  1420. level = -2;
  1421. }
  1422. if(!$(id + '_' + level).length)
  1423. {
  1424. $.getJSON(get + '&json=1', {total:total,level:level}, function(t)
  1425. {
  1426. var check = '';
  1427. if(t.status == 1)
  1428. {
  1429. 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+');">';
  1430. console.log(t.data);
  1431. for(a in t.data)
  1432. {
  1433. if(t.data[a].value)
  1434. {
  1435. check = '';
  1436. if(cur == t.data[a].value)
  1437. {
  1438. check = ' selected';
  1439. }
  1440. html += '<option value="'+t.data[a].value+'" '+check+'>'+t.data[a].name+'</option>';
  1441. }
  1442. }
  1443. html += '</select><span>&nbsp;&nbsp;</span>';
  1444. $(id).append(html);
  1445. $(id + '_' + level).change();
  1446. }
  1447. else
  1448. {
  1449. $(id + '_' + old).nextAll('select').remove();
  1450. $(id + '_' + old).next('span').nextAll('span').remove();
  1451. }
  1452. if($('#' + name + '_level_value').length)
  1453. {
  1454. var total = $(id).find('select').length;
  1455. $('#' + name + '_level_value').val(total);
  1456. }
  1457. if($('#' + name + '_up_value').length)
  1458. {
  1459. $('#' + name + '_up_value').val($(id + '_-2').val());
  1460. }
  1461. });
  1462. }
  1463. }
  1464. */
  1465. //处理更新页面的一些功能,写到一起吧
  1466. var dever_update =
  1467. {
  1468. addIndex : 2,
  1469. index : [],
  1470. auto : false,
  1471. save_key : '',
  1472. init : function()
  1473. {
  1474. var self = this;
  1475. self.index = [];
  1476. // 增加整个更新的表单
  1477. if($(".dever_update_add").length)
  1478. {
  1479. $('.dever_update_add').unbind('click').bind('click', function()
  1480. {
  1481. self.add($(this));
  1482. })
  1483. }
  1484. /* 以后再增加 同时更新另外一个表
  1485. if($(".form-add-content").length)
  1486. {
  1487. var url = config.host + 'auth.password';
  1488. var url = 'http://localhost/dever/manage/?database.update?project=weixin&table=message&menu=weixin&menu_id=39&ajax=1';
  1489. $.get(url, function(t)
  1490. {
  1491. $(".form-add-content").html(t);
  1492. init();
  1493. })
  1494. }
  1495. */
  1496. //增加某一部分表单
  1497. if($(".dever_form_add").length)
  1498. {
  1499. $('.dever_form_add').each(function()
  1500. {
  1501. var key = $.attr('toggle_key');
  1502. if(typeof(self.index[key]) == "undefined")
  1503. {
  1504. self.index[key] = 0;
  1505. }
  1506. $(this).unbind('click').bind('click', function()
  1507. {
  1508. self.append($(this));
  1509. })
  1510. })
  1511. self.del();
  1512. }
  1513. // 开启自动保存
  1514. if($("#struct").length)
  1515. {
  1516. var save = $("#struct").attr('save');
  1517. if(save == 'yes')
  1518. {
  1519. //检测
  1520. self.save_key = location.href + 'test';
  1521. self.check();
  1522. }
  1523. }
  1524. if($('.dever-note').length)
  1525. {
  1526. $('.dever-note').each(function()
  1527. {
  1528. var mditor = new Mditor($(this),{
  1529. fixedHeight:true
  1530. });
  1531. mditor.openPreview();
  1532. })
  1533. }
  1534. },
  1535. save : function()
  1536. {
  1537. //var data = $("#data-1").html();
  1538. var data = [];
  1539. $(".update_value").each(function(i)
  1540. {
  1541. if($(this).attr("update_type") == 'checked')
  1542. {
  1543. data[i] = $(this).get(0).checked;
  1544. }
  1545. else if($(this).attr("update_type") == 'html')
  1546. {
  1547. data[i] = $(this).html();
  1548. }
  1549. else if($(this).attr("update_type") == 'src')
  1550. {
  1551. data[i] = $(this).attr('src');
  1552. }
  1553. else
  1554. {
  1555. data[i] = $(this).val();
  1556. }
  1557. });
  1558. store.set(this.save_key, data.join('|||'));
  1559. //console.info(data);
  1560. },
  1561. recover : function()
  1562. {
  1563. if(confirm('确定恢复上次保存的数据吗?'))
  1564. {
  1565. var data = store.get(this.save_key).split('|||');
  1566. if(data)
  1567. {
  1568. var value = $(".update_value");
  1569. for(var k in data)
  1570. {
  1571. var e = value.eq(k);
  1572. if(e.attr('update_type') == 'checked')
  1573. {
  1574. if(data[k] == 'true')
  1575. {
  1576. e.get(0).checked = true;
  1577. }
  1578. else
  1579. {
  1580. e.get(0).checked = false;
  1581. }
  1582. }
  1583. else if(e.attr('update_type') == 'html')
  1584. {
  1585. e.html(data[k]);
  1586. }
  1587. else if(e.attr('update_type') == 'src')
  1588. {
  1589. e.attr('src', data[k]);
  1590. }
  1591. else
  1592. {
  1593. if(e.attr('id'))
  1594. {
  1595. var id = e.attr('id');
  1596. if(typeof(editors[id]) != "undefined")
  1597. {
  1598. editors[id].setContent(data[k]);
  1599. }
  1600. }
  1601. e.val(data[k]);
  1602. }
  1603. }
  1604. store.set(this.save_key, '');
  1605. this.check();
  1606. }
  1607. }
  1608. },
  1609. check : function()
  1610. {
  1611. var data = store.get(this.save_key);
  1612. var self = this;
  1613. if(data)
  1614. {
  1615. $(".dever_save").unbind('click').bind('click', function()
  1616. {
  1617. self.recover();
  1618. }).show();
  1619. }
  1620. else
  1621. {
  1622. $(".dever_save").hide();
  1623. self.auto = setInterval(function(){self.save()}, 3000);
  1624. }
  1625. },
  1626. del : function()
  1627. {
  1628. var self = this;
  1629. if($(".dever_form_delete").length)
  1630. {
  1631. $('.dever_form_delete').each(function()
  1632. {
  1633. $(this).unbind('click').bind('click', function()
  1634. {
  1635. var parent = $(this).parent();
  1636. var id = parent.attr('id');
  1637. var index = parseInt($('#tab-' + id).attr('toggle_id'));
  1638. var key = $('#tab-' + id).attr('toggle_key');
  1639. if(index <= 1 && self.index[key] <= index)
  1640. {
  1641. }
  1642. else if(index <= 1 && self.index[key] > index)
  1643. {
  1644. index = index+1;
  1645. $("#tab-"+key+"-child-" + index).click();
  1646. }
  1647. else
  1648. {
  1649. index = index-1;
  1650. $("#tab-"+key+"-child-" + index).click();
  1651. };
  1652. $('#tab-' + id).parent().remove();
  1653. parent.remove();
  1654. self.index[key]--;
  1655. })
  1656. })
  1657. }
  1658. },
  1659. append : function(e)
  1660. {
  1661. var self = this;
  1662. var key = e.attr('toggle_key');
  1663. var child = '.dever_'+key+'_child';
  1664. if(typeof(self.index[key]) == "undefined")
  1665. {
  1666. self.index[key] = 0;
  1667. }
  1668. if(self.index[key] <= 0)
  1669. {
  1670. self.index[key] = $(child).length;
  1671. }
  1672. if(self.index[key] > 30)
  1673. {
  1674. alert('最多只能增加30条');
  1675. return;
  1676. }
  1677. var p = e.parent();
  1678. var id = key + '-child-' + self.index[key];
  1679. var name = '第' + (self.index[key]) + '条';
  1680. 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>');
  1681. var e = e.parent().parent();
  1682. var n = e.next();
  1683. var p = e.parent();
  1684. var content = n.html();
  1685. content = content.replaceAll('_c_', '_c_' + (self.index[key]-1) + '_i_');
  1686. content = '<div id="'+id+'" style="display:none;" class="'+n.attr('class')+' dever_form_add_child">' + content + '</div>';
  1687. p.append(content);
  1688. $('#update_' + key +'_c_' + (self.index[key]-1) + '_i_' + 'order_value').val(parseInt($('#update_' + key +'_c_' + (self.index[key]-2) + '_i_' + 'order_value').val())+1);
  1689. self.del();
  1690. //$("html,body").animate({scrollTop:$('.dever_form_add_child').eq(this.appendIndex).offset().top},500);
  1691. self.index[key]++;
  1692. image();
  1693. loadShow();
  1694. autocomplete();
  1695. change();
  1696. },
  1697. add : function(e)
  1698. {
  1699. var self = this;
  1700. var p = e.parent();
  1701. var id = 'data-' + this.addIndex;
  1702. var name = '新增数据-' + (this.addIndex-1);
  1703. p.before('<li><a href="#'+id+'" data-toggle="tab">'+name+'</a></li>');
  1704. var content = $("#myTabContent").find('.tab-pane').eq(0).html();
  1705. content = content.replaceAll('update_', 'update_' + this.addIndex + '__');
  1706. content = '<div class="tab-pane fade" id="'+id+'">' + content + '</div>';
  1707. $("#myTabContent").append(content);
  1708. $('#update_' + this.addIndex + '__where_id').val('-1');
  1709. this.addIndex++;
  1710. }
  1711. }
  1712. String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) {
  1713. if (!RegExp.prototype.isPrototypeOf(reallyDo)) {
  1714. return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi": "g")), replaceWith);
  1715. } else {
  1716. return this.replace(reallyDo, replaceWith);
  1717. }
  1718. }
  1719. Array.prototype.remove = function(val) {
  1720. var index = -1;
  1721. for(var i = 0; i < this.length; i++)
  1722. {
  1723. if(this[i] == val)
  1724. {
  1725. index = i;
  1726. }
  1727. }
  1728. if (index > -1) {
  1729. this.splice(index, 1);
  1730. }
  1731. };
  1732. $.fn.pasteEvents = function( delay ) {
  1733. if (delay == undefined) delay = 20;
  1734. return $(this).each(function() {
  1735. var $el = $(this);
  1736. $el.on("paste", function() {
  1737. $el.trigger("prepaste");
  1738. setTimeout(function() { $el.trigger("postpaste"); }, delay);
  1739. });
  1740. });
  1741. };
  1742. $("textarea").on("postpaste", function()
  1743. {
  1744. if($(this).val().indexOf('<') != -1)
  1745. {
  1746. $(this).val(toMarkdown($(this).val()));
  1747. }
  1748. }).pasteEvents();