main.js 39 KB

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