main.js 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029
  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.split( /,\s*/ );
  697. request.term = term.pop();
  698. if ( request.term in cache ) {
  699. response( cache[ request.term ] );
  700. return;
  701. }
  702. var cate = self.attr('complete_cate');
  703. if (cate) {
  704. request[cate] = $('update_' + cate + '_value').val();
  705. }
  706. $.getJSON(self.attr('complete') + '&callback=?', request, function( data, status, xhr ) {
  707. data = data.data
  708. cache[ term ] = data;
  709. var state = true;
  710. for(var i in data)
  711. {
  712. if(data[i].id <=0)
  713. {
  714. state = false;
  715. }
  716. }
  717. if(state)
  718. {
  719. response( data );
  720. }
  721. });
  722. },
  723. focus: function() {
  724. // prevent value inserted on focus
  725. return false;
  726. },
  727. select: function( event, ui )
  728. {
  729. //log( "Selected: " + ui.item.value + " aka " + ui.item.id );
  730. var value = self.attr('complete_callback');
  731. var id = self.attr('id').replace('_temp', '');
  732. var name = self.attr('name').replace('_temp', '');
  733. //var e = $("#" + id);
  734. var e = self;
  735. var html = '<div style="margin-top: 10px;width: 60%; overflow: auto;max-height: 500px;"><table id="'+id+'_show" class="table table-small-font table-bordered"></table></div>';
  736. if (!$("#" + id + '_show').length) {
  737. e.parent().append(html);
  738. }
  739. if ($("#" + id + '_show').html().indexOf(ui.item.value) == -1)
  740. {
  741. var link = '';
  742. var attr = '';
  743. var pic = '';
  744. if (ui.item['pic']) {
  745. pic = '<a href="javascript:;"><img src="'+ui.item['pic']+'" width="100"></a>';
  746. }
  747. if (ui.item['link']) {
  748. link = ui.item['link'];
  749. attr = ' target="_blank"';
  750. }
  751. var html = '<tr><td width="90%"><input type="checkbox" checked name="'+name+'[]" value="'+ui.item[value]+'"/>&nbsp;&nbsp;'+pic+'<a href="'+link+'" '+attr+' title="'+ui.item.value+'">'+ui.item.value+'</td><td width="10%"><a href="javascript:;" onclick="autocomplete_del($(this), \''+id+'\', \''+ui.item[value]+'\')">[删除]</a></td></tr>';
  752. $("#" + id + '_show').append(html);
  753. autocomplete_value.push(ui.item[value]);
  754. }
  755. ui.item.value = '';
  756. }
  757. });
  758. })
  759. }
  760. }
  761. function autocomplete_del(e, id, value)
  762. {
  763. e.parent().parent().remove();
  764. autocomplete_value.remove(value);
  765. }
  766. //后台通用的提示
  767. function msg(value)
  768. {
  769. $("#dever_modal_no").click();
  770. if(!value.data)
  771. {
  772. value.data = value.msg;
  773. }
  774. if(value == 1)
  775. {
  776. location.reload();
  777. return;
  778. }
  779. submit();
  780. var url = '';
  781. if(value.data != 'reload' && value.status == 2)
  782. {
  783. showAlert(value.msg, false, '错误提示');
  784. //alert(value.data);
  785. //location.reload();
  786. return;
  787. }
  788. else if(value.data == 'reload')
  789. {
  790. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  791. {
  792. pjax({url: location.href, container: config.layout})
  793. }
  794. else
  795. {
  796. location.reload();
  797. }
  798. return;
  799. }
  800. else
  801. {
  802. if(value.data.indexOf('http://') != -1)
  803. {
  804. url = value.data;
  805. }
  806. else if($("#url").length)
  807. {
  808. url = $("#url").val();
  809. }
  810. else
  811. {
  812. notify(value.data)
  813. return;
  814. }
  815. if(url)
  816. {
  817. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  818. {
  819. pjax({url: url, container: config.layout});
  820. }
  821. else
  822. {
  823. location.href = url;
  824. }
  825. }
  826. else
  827. {
  828. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  829. {
  830. pjax({url: location.href, container: config.layout});
  831. }
  832. else
  833. {
  834. location.reload();
  835. }
  836. }
  837. }
  838. return;
  839. }
  840. /**
  841. * 处理多选问题,处理全选按钮
  842. */
  843. function checkbox()
  844. {
  845. if($(".autoload").length)
  846. {
  847. $(".autoload").each(function()
  848. {
  849. if($(this).get(0).checked == true)
  850. {
  851. $(this).removeClass('autoload');
  852. $(this).load();
  853. }
  854. });
  855. }
  856. if($(".autoload_text").length)
  857. {
  858. $(".autoload_text").each(function()
  859. {
  860. if($(this).val())
  861. {
  862. $(this).removeClass('autoload_text');
  863. $(this).load();
  864. }
  865. });
  866. }
  867. var name = 'checkbox-checkall';
  868. var checkbox = $("." + name);
  869. if(checkbox.length)
  870. {
  871. checkbox.unbind('click').bind('click', function()
  872. {
  873. var self = $(this);
  874. $("." + name + "-" + self.val()).each(function()
  875. {
  876. $(this).get(0).checked = self.get(0).checked;
  877. var next = $(this).next();
  878. if($(this).get(0).checked == true)
  879. {
  880. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  881. {
  882. next.attr('disabled', false);
  883. }
  884. if($("#mul_type").length)
  885. {
  886. $("#mul_type").val(1);
  887. }
  888. }
  889. else
  890. {
  891. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  892. {
  893. next.attr('disabled', true);
  894. }
  895. if($("#mul_type").length)
  896. {
  897. $("#mul_type").val(0);
  898. }
  899. }
  900. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
  901. inputShow($(this), 'col');
  902. }
  903. })
  904. });
  905. checkbox.each(function()
  906. {
  907. var self = $(this);
  908. var len = $("." + name + "-" + self.val()).length;
  909. $("." + name + "-" + self.val()).each(function()
  910. {
  911. $(this).unbind('click').bind('click', function()
  912. {
  913. var next = $(this).next();
  914. if($(this).get(0).checked == true)
  915. {
  916. if ($("." + name + "-" + self.val()+":checked").length >= len) {
  917. self.get(0).checked = true;
  918. }
  919. if(self.attr('type') == 'radio')
  920. {
  921. //如果父选项是radio类型,做下限制
  922. //alert(1);
  923. }
  924. if($("#mul_type").length)
  925. {
  926. $("#mul_type").val(1);
  927. }
  928. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  929. {
  930. next.attr('disabled', false);
  931. }
  932. }
  933. else
  934. {
  935. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  936. {
  937. next.attr('disabled', true);
  938. }
  939. }
  940. var num = 0;
  941. $("." + name + "-" + self.val()).each(function()
  942. {
  943. if($(this).get(0).checked == true)
  944. {
  945. num = 1;
  946. }
  947. });
  948. var id = $(this).attr('name');
  949. var hidden = id;
  950. id = id.replace('[]', '');
  951. if(num == 0)
  952. {
  953. self.get(0).checked = false;
  954. if($("#mul_type").length)
  955. {
  956. $("#mul_type").val(0);
  957. }
  958. if (!$('#' + id).length) {
  959. self.parent().append('<input type="hidden" value="0" id="'+id+'" name="'+hidden+'" />');
  960. }
  961. } else {
  962. if ($('#' + id).length) {
  963. $('#' + id).remove();
  964. }
  965. }
  966. })
  967. if($(this).get(0).checked == true)
  968. {
  969. self.get(0).checked = true;
  970. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
  971. inputShow($(this), 'col');
  972. }
  973. }
  974. });
  975. })
  976. }
  977. }
  978. /**
  979. * 处理双击编辑
  980. */
  981. function edit()
  982. {
  983. if($(".edit").length)
  984. {
  985. $(".edit").each(function()
  986. {
  987. $(this).bind('dblclick', function()
  988. {
  989. var col = $(this).attr('data-col');
  990. var project = $(this).attr('data-project');
  991. var table = $(this).attr('data-table');
  992. var url = $(this).attr('data-url');
  993. var id = $(this).attr('data-id');
  994. var html = $(this).attr('data-content');
  995. var type = $(this).attr('data-type');
  996. if($(this).find(".edit-content").length)
  997. {
  998. html = $(this).find(".edit-content").html();
  999. html = html.replace('<!--', '<');
  1000. html = html.replace('-->', '>');
  1001. }
  1002. if(html.indexOf('input') == -1)
  1003. {
  1004. if(type && type == 'textarea')
  1005. {
  1006. $(this).html('<textarea type="text" name="edit" id="edit" rows="10" cols="60">'+html+'</textarea>');
  1007. }
  1008. else
  1009. {
  1010. $(this).html('<input type="text" name="edit" id="edit" value="'+html+'">');
  1011. }
  1012. var self = $(this);
  1013. self.find("#edit").blur(function()
  1014. {
  1015. var value = self.find("#edit").val();
  1016. if(!value)
  1017. {
  1018. alert('不能为空');
  1019. return;
  1020. }
  1021. if($(this).find(".edit-content").length)
  1022. {
  1023. $(this).find(".edit-content").html(value);
  1024. }
  1025. else
  1026. {
  1027. self.attr('data-content', value);
  1028. }
  1029. self.html(value);
  1030. $.post(url, {project:project,table:table,value:value,where_id:id,col:col}, function(t)
  1031. {
  1032. notify('修改成功');
  1033. preview();
  1034. /*
  1035. if(type && type == 'textarea')
  1036. {
  1037. self.html(t);
  1038. }
  1039. */
  1040. })
  1041. })
  1042. }
  1043. });
  1044. })
  1045. }
  1046. }
  1047. function preview()
  1048. {
  1049. if($("#preview").length)
  1050. {
  1051. var time = Date.parse(new Date());
  1052. var src = $('#preview').attr('src').split('#');
  1053. $('#preview').attr('src', src[0] + '&' + time + '#' + src[1]);
  1054. }
  1055. }
  1056. function del()
  1057. {
  1058. if($(".oper_delete").length)
  1059. {
  1060. $(".oper_delete").each(function()
  1061. {
  1062. var href = $(this).attr('href');
  1063. $(this).attr('href', '#');
  1064. $(this).unbind('click');
  1065. $(this).bind('click', function()
  1066. {
  1067. del_act(href);
  1068. });
  1069. })
  1070. }
  1071. }
  1072. /**
  1073. * 处理删除
  1074. */
  1075. function del_act(href)
  1076. {
  1077. if(confirm('确定进行此项操作吗?'))
  1078. {
  1079. $.getJSON(href + '&json=1&callback=?', {}, function(t)
  1080. {
  1081. msg(t);
  1082. })
  1083. }
  1084. }
  1085. /**
  1086. * 处理特殊加载的按钮
  1087. */
  1088. function load(href)
  1089. {
  1090. if(confirm('确定进行此项操作吗?'))
  1091. {
  1092. if(href.indexOf('&') == -1)
  1093. {
  1094. href += '?json=1&callback=?';
  1095. }
  1096. else
  1097. {
  1098. href += '&json=1&callback=?';
  1099. }
  1100. $.getJSON(href, {}, function(t)
  1101. {
  1102. msg(t);
  1103. //location.reload();
  1104. })
  1105. }
  1106. /*
  1107. showAlert('确定进行此项操作吗?', function()
  1108. {
  1109. $("#dever_modal_no").click();
  1110. $.getJSON(href + '&json=1', {}, function(t)
  1111. {
  1112. msg(t);
  1113. })
  1114. });
  1115. */
  1116. }
  1117. /**
  1118. * 处理特殊加载的按钮
  1119. */
  1120. function jump(href, form)
  1121. {
  1122. if (form) {
  1123. var param = formData(form);
  1124. href += param[1];
  1125. }
  1126. location.href = href;
  1127. }
  1128. /**
  1129. * 处理change
  1130. */
  1131. function change()
  1132. {
  1133. if($(".change").length)
  1134. {
  1135. $(".change").each(function()
  1136. {
  1137. var key = $(this).attr('data-child');
  1138. /*
  1139. $('.' + key).each(function()
  1140. {
  1141. if($(this).find('select option:selected').val())
  1142. {
  1143. $(this).show();
  1144. $('#set_cate_id_child').get(0).value = $(this).attr('parent');
  1145. }
  1146. });
  1147. */
  1148. $(this).change(function()
  1149. {
  1150. $('.' + key).hide();
  1151. var v = $('.' + key + '_' + $(this).val());
  1152. var s = v.find('select');
  1153. s.change(function()
  1154. {
  1155. $('.' + key + '_value').val($(this).val());
  1156. })
  1157. if(v.length)
  1158. {
  1159. $('.' + key + '_value').val(s.val());
  1160. v.show();
  1161. }
  1162. else
  1163. {
  1164. $('.' + key + '_value').val(-1);
  1165. }
  1166. });
  1167. if($(this).val() > 0)
  1168. {
  1169. $(this).change();
  1170. }
  1171. });
  1172. }
  1173. }
  1174. /**
  1175. * 处理图库系统
  1176. */
  1177. function image()
  1178. {
  1179. if($(".dever-note").length)
  1180. {
  1181. $(".dever-note").each(function()
  1182. {
  1183. var key = $(this).attr('key');
  1184. $(this).inlineattachment(
  1185. {
  1186. uploadUrl: config.upload + '.drag?key='+ key
  1187. });
  1188. });
  1189. }
  1190. if($(".image_upload").length)
  1191. {
  1192. $(".image_upload").each(function(i)
  1193. {
  1194. var parent = $(this).parent().parent();
  1195. //alert(parent.attr('id'));
  1196. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  1197. {
  1198. return;
  1199. }
  1200. loadUpload(i,$(this),$(this).attr('key'),config.upload + '.start', config.lib + 'upload/');//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  1201. })
  1202. }
  1203. }
  1204. /**
  1205. * 修改密码
  1206. */
  1207. function pass(e)
  1208. {
  1209. var html = '<style>.password_edit div{margin:10px;}.password_edit input{width:200px;}</style><div class="password_edit">';
  1210. html += '<div><span>旧密码:</span><input type="password" class="form-control form_margin" id="edit_old_password" /></div>';
  1211. html += '<div><span>新密码:</span><input type="password" class="form-control form_margin" id="edit_new_password" /></div>';
  1212. html += '</div>';
  1213. $('#dever_modal_body').html(html);
  1214. $('#dever_modal_title').html('修改密码');
  1215. $("#dever_modal_yes").unbind('click').bind('click', function()
  1216. {
  1217. var old_password = $("#edit_old_password").val();
  1218. var new_password = $("#edit_new_password").val();
  1219. if(!old_password || !new_password)
  1220. {
  1221. alert('请输入密码');
  1222. return;
  1223. }
  1224. if(old_password == new_password)
  1225. {
  1226. alert('旧密码和新密码相同');
  1227. return;
  1228. }
  1229. $.post(config.host + 'auth.password', {old:old_password,new:new_password}, function(t)
  1230. {
  1231. alert(t);
  1232. $("#dever_modal_no").click();
  1233. })
  1234. })
  1235. }
  1236. var MSG = [];
  1237. /**
  1238. * 打开弹窗
  1239. */
  1240. //function showMsg(title, e, id, func)
  1241. function showMsg(title, e, id, func, param)
  1242. {
  1243. if(id.indexOf('http://') == -1)
  1244. {
  1245. if($(id).length)
  1246. {
  1247. var html = $(id).html();
  1248. if($(id).html())
  1249. {
  1250. var html = $(id).html();
  1251. MSG[id] = html;
  1252. $(id).html('');
  1253. }
  1254. else
  1255. {
  1256. var html = MSG[id];
  1257. }
  1258. }
  1259. else
  1260. {
  1261. var html = id;
  1262. }
  1263. $('#dever_modal_body').html(html);
  1264. $('#dever_modal_title').html(title);
  1265. if (func) {
  1266. $("#dever_modal_yes").unbind('click').bind('click', func);
  1267. } else {
  1268. $("#dever_modal_yes").unbind('click').bind('click', function(){$("#dever_modal_no").click()});
  1269. }
  1270. }
  1271. else
  1272. {
  1273. var url = id;
  1274. var send = {};
  1275. if (param) {
  1276. send = param;
  1277. }
  1278. if (e && e.attr('msg-send')) {
  1279. send.data = e.attr('msg-send');
  1280. }
  1281. if (url.indexOf('?') != -1) {
  1282. url = url + '&';
  1283. } else {
  1284. url = url + '?';
  1285. }
  1286. $.getJSON(url+'json=1',send,function(t)
  1287. {
  1288. t = t.data;
  1289. $('#dever_modal_body').html(t);
  1290. $('#dever_modal_title').html(title);
  1291. if(func)
  1292. {
  1293. $("#dever_modal_yes").unbind('click').bind('click', func);
  1294. }
  1295. });
  1296. }
  1297. }
  1298. function updateMsg(id)
  1299. {
  1300. $("#"+id).submit();
  1301. }
  1302. function showAlert(msg, func, title)
  1303. {
  1304. if (!title) {
  1305. title = $("#dever-name").html() + '提醒您';
  1306. }
  1307. //$("#dever_modal_no").click();
  1308. $("#dever_modal").modal();
  1309. $('#dever_modal_body').html(msg);
  1310. $('#dever_modal_title').html(title);
  1311. if(func)
  1312. {
  1313. $("#dever_modal_yes").unbind('click').bind('click', func);
  1314. }
  1315. else
  1316. {
  1317. $("#dever_modal_yes").unbind('click').bind('click', function(){$("#dever_modal_no").click()});
  1318. }
  1319. }
  1320. function fastEdit(e, url, title, col)
  1321. {
  1322. var func = function()
  1323. {
  1324. submit_action();
  1325. };
  1326. var send = {};
  1327. send.col = col;
  1328. $.get(url,send,function(t)
  1329. {
  1330. var html = $(t).find('form').prop("outerHTML");
  1331. var valid = $(t).find('#valid').prop("outerHTML");
  1332. html = html + valid;
  1333. showAlert(html, func, title);
  1334. $('#update_button').hide();
  1335. init();
  1336. });
  1337. }
  1338. /*
  1339. var test =
  1340. {
  1341. refreshPage: false,
  1342. addAjaxFlag: true,
  1343. //添加收藏
  1344. add: function(cfg)
  1345. {
  1346. }
  1347. }
  1348. */
  1349. function showToggle(e)
  1350. {
  1351. var id = e.attr('toggle');
  1352. var child = e.attr('toggle_child');
  1353. var parent = e.parent();
  1354. parent.parent().find('li').removeClass('active');
  1355. parent.addClass('active');
  1356. $(child).fadeOut(100);
  1357. $(id).fadeIn(500);
  1358. initEditor($(id).find('.editor'));
  1359. }
  1360. function select_linkage(level, id, url, name, value, valid, w, total, search, level_param)
  1361. {
  1362. var e = '#' + id;
  1363. var parent = value.split(',');
  1364. var cur = parent[0];
  1365. parent.remove(cur);
  1366. value = parent.join(',');
  1367. var html = '';
  1368. var old = level;
  1369. if (!total) {
  1370. level_id = 0;
  1371. } else {
  1372. if (level >= total) {
  1373. //$(e).show();
  1374. return;
  1375. }
  1376. level_id = $(e + '_' + level).val();
  1377. level = parseInt(level) + 1;
  1378. }
  1379. $.getJSON(url + '?json=1', {level_search:search, level_id:level_id, level_num:level,level_param:level_param}, function(t) {
  1380. var check = '';
  1381. if (t.status == 1) {
  1382. var total = t.data.level_total;
  1383. var data = t.data.list;
  1384. if(!$(e + '_' + level).length) {
  1385. 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+'\');">';
  1386. }
  1387. for (a in data) {
  1388. if (data[a].value) {
  1389. check = '';
  1390. if (cur == data[a].value) {
  1391. check = ' selected';
  1392. }
  1393. html += '<option value="'+data[a].value+'" '+check+'>'+data[a].name+'</option>';
  1394. }
  1395. }
  1396. if(!$(e + '_' + level).length) {
  1397. html += '</select><span>&nbsp;&nbsp;</span>';
  1398. $(e).append(html);
  1399. $(e + '_' + level).change();
  1400. } else {
  1401. $(e + '_' + level).html(html);
  1402. $(e + '_' + level).change();
  1403. }
  1404. } else {
  1405. $(e + '_' + old).nextAll('select').remove();
  1406. $(e + '_' + old).next('span').nextAll('span').remove();
  1407. }
  1408. /*
  1409. if ($('#' + name + '_level_value').length) {
  1410. var total = $(id).find('select').length;
  1411. $('#' + name + '_level_value').val(total);
  1412. }
  1413. if ($('#' + name + '_up_value').length) {
  1414. $('#' + name + '_up_value').val($(id + '_-2').val());
  1415. }
  1416. */
  1417. });
  1418. }
  1419. /*
  1420. function select_mul(level, id, url, name, value, valid, w, num)
  1421. {
  1422. if(level == 0)
  1423. {
  1424. $(id).find('select').remove();
  1425. $(id).find('span').remove();
  1426. return;
  1427. }
  1428. var parent = value.split(',');
  1429. var cur = parent[0];
  1430. parent.remove(cur);
  1431. value = parent.join(',');
  1432. var html = '';
  1433. var old = level;
  1434. if(level != -1)
  1435. {
  1436. if($(id + '_' + level).length)
  1437. {
  1438. level = $(id + '_' + level).val();
  1439. }
  1440. alert(level);
  1441. if(level == 0)
  1442. {
  1443. $(id + '_' + old).nextAll('select').remove();
  1444. $(id + '_' + old).next('span').nextAll('span').remove();
  1445. if($('#' + name + '_level_value').length)
  1446. {
  1447. var total = $(id).find('select').length;
  1448. $('#' + name + '_level_value').val(total);
  1449. }
  1450. if(old == -2 && $('#' + name + '_value_value').length)
  1451. {
  1452. $('#' + name + '_value_value').val(level);
  1453. }
  1454. return;
  1455. }
  1456. if(old == -2)
  1457. {
  1458. $(id + '_' + old).nextAll('select').remove();
  1459. $(id + '_' + old).next('span').nextAll('span').remove();
  1460. }
  1461. if($('#' + name + '_value_value').length)
  1462. {
  1463. $('#' + name + '_value_value').val(level);
  1464. }
  1465. }
  1466. var total = $(id).find('select').length;
  1467. if(num > 0 && total >= num)
  1468. {
  1469. return;
  1470. }
  1471. var get = url.replace('{level}', level);
  1472. if(level == -1)
  1473. {
  1474. level = -2;
  1475. }
  1476. if(!$(id + '_' + level).length)
  1477. {
  1478. $.getJSON(get + '&json=1', {total:total,level:level}, function(t)
  1479. {
  1480. var check = '';
  1481. if(t.status == 1)
  1482. {
  1483. 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+');">';
  1484. console.log(t.data);
  1485. for(a in t.data)
  1486. {
  1487. if(t.data[a].value)
  1488. {
  1489. check = '';
  1490. if(cur == t.data[a].value)
  1491. {
  1492. check = ' selected';
  1493. }
  1494. html += '<option value="'+t.data[a].value+'" '+check+'>'+t.data[a].name+'</option>';
  1495. }
  1496. }
  1497. html += '</select><span>&nbsp;&nbsp;</span>';
  1498. $(id).append(html);
  1499. $(id + '_' + level).change();
  1500. }
  1501. else
  1502. {
  1503. $(id + '_' + old).nextAll('select').remove();
  1504. $(id + '_' + old).next('span').nextAll('span').remove();
  1505. }
  1506. if($('#' + name + '_level_value').length)
  1507. {
  1508. var total = $(id).find('select').length;
  1509. $('#' + name + '_level_value').val(total);
  1510. }
  1511. if($('#' + name + '_up_value').length)
  1512. {
  1513. $('#' + name + '_up_value').val($(id + '_-2').val());
  1514. }
  1515. });
  1516. }
  1517. }
  1518. */
  1519. //处理更新页面的一些功能,写到一起吧
  1520. var dever_update =
  1521. {
  1522. addIndex : 2,
  1523. index : [],
  1524. auto : false,
  1525. save_key : '',
  1526. init : function()
  1527. {
  1528. var self = this;
  1529. self.index = [];
  1530. // 增加整个更新的表单
  1531. if($(".dever_update_add").length)
  1532. {
  1533. $('.dever_update_add').unbind('click').bind('click', function()
  1534. {
  1535. self.add($(this));
  1536. })
  1537. }
  1538. /* 以后再增加 同时更新另外一个表
  1539. if($(".form-add-content").length)
  1540. {
  1541. var url = config.host + 'auth.password';
  1542. var url = 'http://localhost/dever/manage/?database.update?project=weixin&table=message&menu=weixin&menu_id=39&ajax=1';
  1543. $.get(url, function(t)
  1544. {
  1545. $(".form-add-content").html(t);
  1546. init();
  1547. })
  1548. }
  1549. */
  1550. //增加某一部分表单
  1551. if($(".dever_form_add").length)
  1552. {
  1553. $('.dever_form_add').each(function()
  1554. {
  1555. var key = $.attr('toggle_key');
  1556. if(typeof(self.index[key]) == "undefined")
  1557. {
  1558. self.index[key] = 0;
  1559. }
  1560. $(this).unbind('click').bind('click', function()
  1561. {
  1562. self.append($(this));
  1563. })
  1564. })
  1565. self.del();
  1566. }
  1567. // 开启自动保存
  1568. if($("#struct").length)
  1569. {
  1570. var save = $("#struct").attr('save');
  1571. if(save == 'yes')
  1572. {
  1573. //检测
  1574. self.save_key = location.href + 'test';
  1575. self.check();
  1576. }
  1577. }
  1578. if($('.dever-note').length)
  1579. {
  1580. $('.dever-note').each(function()
  1581. {
  1582. var mditor = new Mditor($(this),{
  1583. fixedHeight:true
  1584. });
  1585. mditor.openPreview();
  1586. })
  1587. }
  1588. },
  1589. save : function()
  1590. {
  1591. //var data = $("#data-1").html();
  1592. var data = [];
  1593. $(".update_value").each(function(i)
  1594. {
  1595. if($(this).attr("update_type") == 'checked')
  1596. {
  1597. data[i] = $(this).get(0).checked;
  1598. }
  1599. else if($(this).attr("update_type") == 'html')
  1600. {
  1601. data[i] = $(this).html();
  1602. }
  1603. else if($(this).attr("update_type") == 'src')
  1604. {
  1605. data[i] = $(this).attr('src');
  1606. }
  1607. else
  1608. {
  1609. data[i] = $(this).val();
  1610. }
  1611. });
  1612. store.set(this.save_key, data.join('|||'));
  1613. //console.info(data);
  1614. },
  1615. recover : function()
  1616. {
  1617. if(confirm('确定恢复上次保存的数据吗?'))
  1618. {
  1619. var data = store.get(this.save_key).split('|||');
  1620. if(data)
  1621. {
  1622. var value = $(".update_value");
  1623. for(var k in data)
  1624. {
  1625. var e = value.eq(k);
  1626. if(e.attr('update_type') == 'checked')
  1627. {
  1628. if(data[k] == 'true')
  1629. {
  1630. e.get(0).checked = true;
  1631. }
  1632. else
  1633. {
  1634. e.get(0).checked = false;
  1635. }
  1636. }
  1637. else if(e.attr('update_type') == 'html')
  1638. {
  1639. e.html(data[k]);
  1640. }
  1641. else if(e.attr('update_type') == 'src')
  1642. {
  1643. e.attr('src', data[k]);
  1644. }
  1645. else
  1646. {
  1647. if(e.attr('id'))
  1648. {
  1649. var id = e.attr('id');
  1650. if(typeof(editors[id]) != "undefined")
  1651. {
  1652. editors[id].html(data[k]);
  1653. }
  1654. }
  1655. e.val(data[k]);
  1656. }
  1657. }
  1658. store.set(this.save_key, '');
  1659. this.check();
  1660. }
  1661. }
  1662. },
  1663. check : function()
  1664. {
  1665. var data = store.get(this.save_key);
  1666. var self = this;
  1667. if(data)
  1668. {
  1669. $(".dever_save").unbind('click').bind('click', function()
  1670. {
  1671. self.recover();
  1672. }).show();
  1673. }
  1674. else
  1675. {
  1676. $(".dever_save").hide();
  1677. self.auto = setInterval(function(){self.save()}, 3000);
  1678. }
  1679. },
  1680. del : function()
  1681. {
  1682. var self = this;
  1683. if($(".dever_form_delete").length)
  1684. {
  1685. $('.dever_form_delete').each(function()
  1686. {
  1687. $(this).unbind('click').bind('click', function()
  1688. {
  1689. var parent = $(this).parent();
  1690. var id = parent.attr('id');
  1691. var index = parseInt($('#tab-' + id).attr('toggle_id'));
  1692. var key = $('#tab-' + id).attr('toggle_key');
  1693. if(index <= 1 && self.index[key] <= index)
  1694. {
  1695. }
  1696. else if(index <= 1 && self.index[key] > index)
  1697. {
  1698. index = index+1;
  1699. $("#tab-"+key+"-child-" + index).click();
  1700. }
  1701. else
  1702. {
  1703. index = index-1;
  1704. $("#tab-"+key+"-child-" + index).click();
  1705. };
  1706. $('#tab-' + id).parent().remove();
  1707. parent.remove();
  1708. self.index[key]--;
  1709. })
  1710. })
  1711. }
  1712. },
  1713. append : function(e)
  1714. {
  1715. var self = this;
  1716. var key = e.attr('toggle_key');
  1717. var child = '.dever_'+key+'_child';
  1718. if(typeof(self.index[key]) == "undefined")
  1719. {
  1720. self.index[key] = 0;
  1721. }
  1722. if(self.index[key] <= 0)
  1723. {
  1724. self.index[key] = $(child).length;
  1725. }
  1726. if(self.index[key] > 30)
  1727. {
  1728. alert('最多只能增加30条');
  1729. return;
  1730. }
  1731. var p = e.parent();
  1732. var id = key + '-child-' + self.index[key];
  1733. var name = '第' + (self.index[key]) + '条';
  1734. 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>');
  1735. var e = e.parent().parent();
  1736. var n = e.next();
  1737. var p = e.parent();
  1738. var content = n.html();
  1739. content = content.replaceAll('_c_', '_c_' + (self.index[key]-1) + '_i_');
  1740. content = '<div id="'+id+'" style="display:none;" class="'+n.attr('class')+' dever_form_add_child">' + content + '</div>';
  1741. p.append(content);
  1742. $('#update_' + key +'_c_' + (self.index[key]-1) + '_i_' + 'order_value').val(parseInt($('#update_' + key +'_c_' + (self.index[key]-2) + '_i_' + 'order_value').val())+1);
  1743. self.del();
  1744. //$("html,body").animate({scrollTop:$('.dever_form_add_child').eq(this.appendIndex).offset().top},500);
  1745. self.index[key]++;
  1746. image();
  1747. loadShow();
  1748. autocomplete();
  1749. change();
  1750. },
  1751. add : function(e)
  1752. {
  1753. var self = this;
  1754. var p = e.parent();
  1755. var id = 'data-' + this.addIndex;
  1756. var name = '新增数据-' + (this.addIndex-1);
  1757. p.before('<li><a href="#'+id+'" data-toggle="tab">'+name+'</a></li>');
  1758. var content = $("#myTabContent").find('.tab-pane').eq(0).html();
  1759. content = content.replaceAll('update_', 'update_' + this.addIndex + '__');
  1760. content = '<div class="tab-pane fade" id="'+id+'">' + content + '</div>';
  1761. $("#myTabContent").append(content);
  1762. $('#update_' + this.addIndex + '__where_id').val('-1');
  1763. this.addIndex++;
  1764. }
  1765. }
  1766. String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) {
  1767. if (!RegExp.prototype.isPrototypeOf(reallyDo)) {
  1768. return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi": "g")), replaceWith);
  1769. } else {
  1770. return this.replace(reallyDo, replaceWith);
  1771. }
  1772. }
  1773. Array.prototype.remove = function(val) {
  1774. var index = -1;
  1775. for(var i = 0; i < this.length; i++)
  1776. {
  1777. if(this[i] == val)
  1778. {
  1779. index = i;
  1780. }
  1781. }
  1782. if (index > -1) {
  1783. this.splice(index, 1);
  1784. }
  1785. };
  1786. $.fn.pasteEvents = function( delay ) {
  1787. if (delay == undefined) delay = 20;
  1788. return $(this).each(function() {
  1789. var $el = $(this);
  1790. $el.on("paste", function() {
  1791. $el.trigger("prepaste");
  1792. setTimeout(function() { $el.trigger("postpaste"); }, delay);
  1793. });
  1794. });
  1795. };
  1796. $("textarea").on("postpaste", function()
  1797. {
  1798. if($(this).val().indexOf('<') != -1)
  1799. {
  1800. $(this).val(toMarkdown($(this).val()));
  1801. }
  1802. }).pasteEvents();