main.js 31 KB

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