main.js 38 KB

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