main.js 38 KB

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