main.js 38 KB

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