main.js 32 KB

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