main.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071
  1. var editors = [];
  2. $(document).ready(function()
  3. {
  4. init();
  5. });
  6. function init()
  7. {
  8. edit();
  9. del();
  10. checkbox();
  11. image();
  12. change();
  13. autocomplete();
  14. template();
  15. submit();
  16. loadShow();
  17. initEditor();
  18. //更新页面一些功能,上边的一些功能等找时间再优化吧
  19. Maze_update.init();
  20. }
  21. function initEditor()
  22. {
  23. if($('.editor').length)
  24. {
  25. $('.editor').each(function()
  26. {
  27. var parent = $(this).parent().parent();
  28. //alert(parent.attr('id'));
  29. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  30. {
  31. return;
  32. }
  33. loadEditor($(this));
  34. })
  35. }
  36. }
  37. function loadEditor(e)
  38. {
  39. if(!e.length)
  40. {
  41. return;
  42. }
  43. var id = e.attr('id');
  44. var key = e.attr('key');
  45. if(typeof(UM) == "undefined")
  46. {
  47. var u = UE;
  48. }
  49. else
  50. {
  51. var u = UM;
  52. }
  53. if(typeof(editors[id]) == "undefined")
  54. {
  55. editors[id] = u.getEditor(id,
  56. {
  57. imageUrl : config.upload + '.ueditor?key=' + key
  58. });
  59. }
  60. }
  61. //更新页面的提交按钮
  62. function submit()
  63. {
  64. if($(".save-data").length)
  65. {
  66. $(".save-data").bind('click', function()
  67. {
  68. $(".form1").submit();
  69. //$(this).unbind('click');
  70. })
  71. }
  72. }
  73. //头部菜单
  74. function topMenu(e)
  75. {
  76. var p = e.parent().parent().parent().find('span');
  77. p.html(e.html());
  78. //更新当前的精细权限
  79. var url = config.host + 'top.update_action?json=1';
  80. var id = e.attr('data-id');
  81. $.post(url, {id:id}, function(t)
  82. {
  83. if(location.href.indexOf('where_id') != -1)
  84. {
  85. var href = location.href.split('where_id');
  86. location.href = href[0] + 'where_id=' + t;
  87. }
  88. else
  89. {
  90. location.reload();
  91. }
  92. })
  93. }
  94. //更新页面的批量载入选择
  95. function loadShow()
  96. {
  97. if($(".show_input").length)
  98. {
  99. $(".show_input input").each(function()
  100. {
  101. if($(this).attr('checked'))
  102. {
  103. $(this).click().attr('checked',true);
  104. }
  105. })
  106. }
  107. }
  108. function inputShow(e,n)
  109. {
  110. var item = e.parent().find('input');
  111. $(".show_" + n).hide();
  112. var array = ['input', 'textarea'];
  113. for(var a in array)
  114. {
  115. $(".show_" + n).find(array[a]).removeClass('validate[required]');
  116. }
  117. item.each(function()
  118. {
  119. if($(this).get(0).checked == true)
  120. {
  121. inputShowOne($(this),n);
  122. }
  123. });
  124. }
  125. function inputShowOne(e,n)
  126. {
  127. var value = e.val();
  128. //$(".show_" + n).hide();
  129. //$(".show_" + n + '_' + value).attr('style','color:red').show();
  130. $(".show_" + n + '_' + value).show();
  131. var array = ['input', 'textarea'];
  132. for(var a in array)
  133. {
  134. if($(".show_" + n + '_' + value).length && $(".show_" + n + '_' + value).attr('class').indexOf('show_no') == -1)
  135. {
  136. $(".show_" + n + '_' + value).find(array[a]).each(function()
  137. {
  138. var parent = $(this).parent();
  139. if($(this).attr('class') != 'editor' && parent.find('label').length && parent.find('label').html().indexOf('选填') == -1)
  140. {
  141. $(this).addClass('validate[required]');
  142. }
  143. })
  144. }
  145. }
  146. }
  147. //批量更新
  148. function list_mul(e)
  149. {
  150. var type = parseInt($("#mul_type").val());
  151. if(type != 1 && type != 2)
  152. {
  153. alert('您还没有选择数据更新方式');
  154. return;
  155. }
  156. if(confirm('确定进行此项操作吗?'))
  157. {
  158. //e.html('更新中').unbind('click');
  159. $('#method').val('mul');
  160. $('#function').val('msg');
  161. $('#form1').attr('target', 'f1').submit();
  162. }
  163. }
  164. //搜索
  165. function list_search(e)
  166. {
  167. $('#method').val('search');
  168. $('#function').val('');
  169. $('#form1').attr('target', '').submit();
  170. }
  171. //更新数据
  172. function update(e, id, key, table)
  173. {
  174. var col = e.attr('name');
  175. var value = e.val();
  176. var url = config.host + 'database.update_action?json=1';
  177. $.post(url, {where_id:id,col:col,value:value,key:key,table:table}, function(t)
  178. {
  179. notice('操作已成功!您的操作已修改当前选项!');
  180. })
  181. }
  182. function notice(msg)
  183. {
  184. var notice = new PNotify({
  185. title: '提示信息',
  186. text: msg,
  187. buttons: {
  188. closer: false,
  189. sticker: false
  190. }
  191. });
  192. notice.get().click(function() {
  193. notice.remove();
  194. });
  195. }
  196. //模板选择
  197. function template()
  198. {
  199. if(config.template)
  200. {
  201. $('body').attr('class', 'theme-' + config.template);
  202. }
  203. if($(".selector").length)
  204. {
  205. $(".selector").each(function()
  206. {
  207. if($(this).data('check') == 'checked')
  208. {
  209. selector($(this));
  210. }
  211. })
  212. }
  213. }
  214. //选择器
  215. function selector(e)
  216. {
  217. var value = e.data('value');
  218. var name = e.data('name');
  219. $('#'+name+'_value').val(value);
  220. $('.'+name+'_selector').children().css({'border':'1px solid #ccc'});
  221. e.children().css({'border':'1px solid black'});
  222. if(name == 'update_template')
  223. {
  224. $('body').attr('class', 'theme-' + value);
  225. }
  226. }
  227. function autocomplete()
  228. {
  229. if($("input[complete]").length)
  230. {
  231. $("input[complete]").each(function()
  232. {
  233. var cache = {};
  234. var self = $(this);
  235. self.autocomplete(
  236. {
  237. minLength: 2,
  238. source: function( request, response )
  239. {
  240. var term = request.term;
  241. if ( term in cache ) {
  242. response( cache[ term ] );
  243. return;
  244. }
  245. $.getJSON(self.attr('complete') + '&callback=?', request, function( data, status, xhr ) {
  246. console.info(data);
  247. cache[ term ] = data;
  248. response( data );
  249. });
  250. }
  251. });
  252. })
  253. }
  254. }
  255. //后台通用的提示
  256. function msg(value)
  257. {
  258. var url = '';
  259. if(value.msg != 'reload' && value.status == 2)
  260. {
  261. submit();
  262. //showAlert(value.msg);
  263. alert(value.msg);
  264. location.reload();
  265. return;
  266. }
  267. else
  268. {
  269. if(value.msg.indexOf('http://') != -1)
  270. {
  271. url = value.msg;
  272. }
  273. else if($("#url").length)
  274. {
  275. url = $("#url").val();
  276. }
  277. else
  278. {
  279. notice(value.msg);
  280. return;
  281. }
  282. if(url)
  283. {
  284. location.href = url;
  285. }
  286. else
  287. {
  288. location.reload();
  289. }
  290. }
  291. return;
  292. }
  293. /**
  294. * 处理多选问题,处理全选按钮
  295. */
  296. function checkbox()
  297. {
  298. var name = 'checkbox-checkall';
  299. var checkbox = $("." + name);
  300. if(checkbox.length)
  301. {
  302. checkbox.click(function()
  303. {
  304. var self = $(this);
  305. $("." + name + "-" + self.val()).each(function()
  306. {
  307. $(this).get(0).checked = self.get(0).checked;
  308. var next = $(this).next();
  309. if($(this).get(0).checked == true)
  310. {
  311. if(next.length)
  312. {
  313. next.attr('disabled', false);
  314. }
  315. if($("#mul_type").length)
  316. {
  317. $("#mul_type").val(1);
  318. }
  319. }
  320. else
  321. {
  322. if(next.length)
  323. {
  324. next.attr('disabled', true);
  325. }
  326. if($("#mul_type").length)
  327. {
  328. $("#mul_type").val(0);
  329. }
  330. }
  331. })
  332. });
  333. checkbox.each(function()
  334. {
  335. var self = $(this);
  336. $("." + name + "-" + self.val()).each(function()
  337. {
  338. $(this).click(function()
  339. {
  340. var next = $(this).next();
  341. if($(this).get(0).checked == true)
  342. {
  343. self.get(0).checked = true;
  344. if(self.attr('type') == 'radio')
  345. {
  346. //如果父选项是radio类型,做下限制
  347. //alert(1);
  348. }
  349. if($("#mul_type").length)
  350. {
  351. $("#mul_type").val(1);
  352. }
  353. if(next.length)
  354. {
  355. next.attr('disabled', false);
  356. }
  357. }
  358. else
  359. {
  360. //子选项取消时,处理一下父级选项
  361. var num = 0;
  362. $("." + name + "-" + self.val()).each(function()
  363. {
  364. if($(this).get(0).checked == true)
  365. {
  366. num = 1;
  367. }
  368. });
  369. if(num == 0)
  370. {
  371. self.get(0).checked = false;
  372. if($("#mul_type").length)
  373. {
  374. $("#mul_type").val(0);
  375. }
  376. }
  377. if(next.length)
  378. {
  379. next.attr('disabled', true);
  380. }
  381. }
  382. })
  383. if($(this).get(0).checked == true)
  384. {
  385. self.get(0).checked = true;
  386. }
  387. });
  388. })
  389. }
  390. }
  391. /**
  392. * 处理双击编辑
  393. */
  394. function edit()
  395. {
  396. if($(".edit").length)
  397. {
  398. $(".edit").each(function()
  399. {
  400. $(this).bind('dblclick', function()
  401. {
  402. var col = $(this).attr('data-col');
  403. var key = $(this).attr('data-key');
  404. var table = $(this).attr('data-table');
  405. var url = $(this).attr('data-url');
  406. var id = $(this).attr('data-id');
  407. var html = $(this).attr('data-content');
  408. var type = $(this).attr('data-type');
  409. if($(this).find(".edit-content").length)
  410. {
  411. html = $(this).find(".edit-content").html();
  412. html = html.replace('<!--', '<');
  413. html = html.replace('-->', '>');
  414. }
  415. if(html.indexOf('input') == -1)
  416. {
  417. if(type && type == 'textarea')
  418. {
  419. $(this).html('<textarea type="text" name="edit" id="edit" rows="20" cols="80">'+html+'</textarea>');
  420. }
  421. else
  422. {
  423. $(this).html('<input type="text" name="edit" id="edit" value="'+html+'">');
  424. }
  425. var self = $(this);
  426. self.find("#edit").blur(function()
  427. {
  428. var value = self.find("#edit").val();
  429. if(!value)
  430. {
  431. alert('不能为空');
  432. return;
  433. }
  434. if($(this).find(".edit-content").length)
  435. {
  436. $(this).find(".edit-content").html(value);
  437. }
  438. else
  439. {
  440. self.attr('data-content', value);
  441. }
  442. self.html(value);
  443. $.post(url, {key:key,table:table,value:value,where_id:id,col:col}, function(t)
  444. {
  445. notice('修改成功');
  446. /*
  447. if(type && type == 'textarea')
  448. {
  449. self.html(t);
  450. }
  451. */
  452. })
  453. })
  454. }
  455. });
  456. })
  457. }
  458. }
  459. function del()
  460. {
  461. if($(".oper_6").length)
  462. {
  463. $(".oper_6").each(function()
  464. {
  465. var href = $(this).attr('href');
  466. $(this).attr('href', '#');
  467. $(this).unbind('click');
  468. $(this).bind('click', function()
  469. {
  470. del_act(href);
  471. });
  472. })
  473. }
  474. }
  475. /**
  476. * 处理删除
  477. */
  478. function del_act(href)
  479. {
  480. if(confirm('确定进行此项操作吗?'))
  481. {
  482. $.getJSON(href, {}, function(t)
  483. {
  484. msg(t);
  485. })
  486. }
  487. }
  488. /**
  489. * 处理特殊加载的按钮
  490. */
  491. function load(href)
  492. {
  493. if(confirm('确定进行此项操作吗?'))
  494. {
  495. if(href.indexOf('&') == -1)
  496. {
  497. href += '?callback=?';
  498. }
  499. else
  500. {
  501. href += '&callback=?';
  502. }
  503. $.getJSON(href, {}, function(t)
  504. {
  505. msg(t);
  506. //location.reload();
  507. })
  508. }
  509. /*
  510. showAlert('确定进行此项操作吗?', function()
  511. {
  512. $("#maze_modal_no").click();
  513. $.getJSON(href + '&json=1', {}, function(t)
  514. {
  515. msg(t);
  516. })
  517. });
  518. */
  519. }
  520. /**
  521. * 处理特殊加载的按钮
  522. */
  523. function jump(href)
  524. {
  525. location.href = href;
  526. }
  527. /**
  528. * 处理change
  529. */
  530. function change()
  531. {
  532. if($(".change").length)
  533. {
  534. $(".change").each(function()
  535. {
  536. var key = $(this).attr('data-child');
  537. /*
  538. $('.' + key).each(function()
  539. {
  540. if($(this).find('select option:selected').val())
  541. {
  542. $(this).show();
  543. $('#set_cate_id_child').get(0).value = $(this).attr('parent');
  544. }
  545. });
  546. */
  547. $(this).change(function()
  548. {
  549. $('.' + key).hide();
  550. var v = $('.' + key + '_' + $(this).val());
  551. var s = v.find('select');
  552. s.change(function()
  553. {
  554. $('.' + key + '_value').val($(this).val());
  555. })
  556. if(v.length)
  557. {
  558. $('.' + key + '_value').val(s.val());
  559. v.show();
  560. }
  561. else
  562. {
  563. $('.' + key + '_value').val(-1);
  564. }
  565. });
  566. if($(this).val() > 0)
  567. {
  568. $(this).change();
  569. }
  570. });
  571. }
  572. }
  573. /**
  574. * 处理图库系统
  575. */
  576. function image()
  577. {
  578. if($(".image_upload").length)
  579. {
  580. $(".image_upload").each(function(i)
  581. {
  582. var parent = $(this).parent().parent();
  583. //alert(parent.attr('id'));
  584. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  585. {
  586. return;
  587. }
  588. loadUpload(i,$(this),$(this).attr('key'),config.upload + '.start', config.lib + 'upload/');//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  589. })
  590. }
  591. }
  592. /**
  593. * 修改密码
  594. */
  595. function pass(e)
  596. {
  597. var html = '<style>.password_edit div{margin:10px;}.password_edit input{width:200px;}</style><div class="password_edit">';
  598. html += '<div><span>旧密码:</span><input type="password" class="form-control" id="edit_old_password" /></div>';
  599. html += '<div><span>新密码:</span><input type="password" class="form-control" id="edit_new_password" /></div>';
  600. html += '</div>';
  601. $('#maze_modal_body').html(html);
  602. $('#maze_modal_title').html('修改密码');
  603. $("#maze_modal_yes").unbind('click').bind('click', function()
  604. {
  605. var old_password = $("#edit_old_password").val();
  606. var new_password = $("#edit_new_password").val();
  607. if(!old_password || !new_password)
  608. {
  609. alert('请输入密码');
  610. return;
  611. }
  612. if(old_password == new_password)
  613. {
  614. alert('旧密码和新密码相同');
  615. return;
  616. }
  617. $.post(config.host + 'auth.password', {old:old_password,new:new_password}, function(t)
  618. {
  619. alert(t);
  620. $("#maze_modal_no").click();
  621. })
  622. })
  623. }
  624. var MSG = [];
  625. /**
  626. * 打开弹窗
  627. */
  628. function showMsg(title, e, id, func)
  629. {
  630. var html = $(id).html();
  631. if($(id).html())
  632. {
  633. var html = $(id).html();
  634. MSG[id] = html;
  635. $(id).html('');
  636. }
  637. else
  638. {
  639. var html = MSG[id];
  640. }
  641. $('#maze_modal_body').html(html);
  642. $('#maze_modal_title').html(title);
  643. if(func)
  644. {
  645. $("#maze_modal_yes").unbind('click').bind('click', func);
  646. }
  647. }
  648. function showAlert(msg, func)
  649. {
  650. //$("#maze_modal_no").click();
  651. $("#maze_modal").modal();
  652. $('#maze_modal_body').html(msg);
  653. $('#maze_modal_title').html('提醒您');
  654. if(func)
  655. {
  656. $("#maze_modal_yes").unbind('click').bind('click', func);
  657. }
  658. else
  659. {
  660. $("#maze_modal_yes").unbind('click').bind('click', function(){$("#maze_modal_no").click()});
  661. }
  662. }
  663. /*
  664. var test =
  665. {
  666. refreshPage: false,
  667. addAjaxFlag: true,
  668. //添加收藏
  669. add: function(cfg)
  670. {
  671. }
  672. }
  673. */
  674. function showToggle(e)
  675. {
  676. var id = e.attr('toggle');
  677. var child = e.attr('toggle_child');
  678. var parent = e.parent();
  679. parent.parent().find('li').removeClass('active');
  680. parent.addClass('active');
  681. $(child).fadeOut(100);
  682. $(id).fadeIn(500);
  683. loadEditor($(id).find('.editor'));
  684. }
  685. //处理更新页面的一些功能,写到一起吧
  686. var Maze_update =
  687. {
  688. addIndex : 2,
  689. index : [],
  690. auto : false,
  691. save_key : '',
  692. init : function()
  693. {
  694. var self = this;
  695. // 增加整个更新的表单
  696. if($(".maze_update_add").length)
  697. {
  698. $('.maze_update_add').unbind('click').bind('click', function()
  699. {
  700. self.add($(this));
  701. })
  702. }
  703. /* 以后再增加 同时更新另外一个表
  704. if($(".form-add-content").length)
  705. {
  706. var url = config.host + 'auth.password';
  707. var url = 'http://localhost/mazephp/manage/?database.update?key=weixin&table=message&menu=weixin&menu_id=39&ajax=1';
  708. $.get(url, function(t)
  709. {
  710. $(".form-add-content").html(t);
  711. init();
  712. })
  713. }
  714. */
  715. //增加某一部分表单
  716. if($(".maze_form_add").length)
  717. {
  718. $('.maze_form_add').each(function()
  719. {
  720. var key = $.attr('toggle_key');
  721. if(typeof(self.index[key]) == "undefined")
  722. {
  723. self.index[key] = 0;
  724. }
  725. $(this).unbind('click').bind('click', function()
  726. {
  727. self.append($(this));
  728. })
  729. })
  730. self.del();
  731. }
  732. // 开启自动保存
  733. if($("#struct").length)
  734. {
  735. var save = $("#struct").attr('save');
  736. if(save == 'yes')
  737. {
  738. //检测
  739. self.save_key = location.href + 'test';
  740. self.check();
  741. }
  742. }
  743. },
  744. save : function()
  745. {
  746. //var data = $("#data-1").html();
  747. var data = [];
  748. $(".update_value").each(function(i)
  749. {
  750. if($(this).attr("update_type") == 'checked')
  751. {
  752. data[i] = $(this).get(0).checked;
  753. }
  754. else if($(this).attr("update_type") == 'html')
  755. {
  756. data[i] = $(this).html();
  757. }
  758. else if($(this).attr("update_type") == 'src')
  759. {
  760. data[i] = $(this).attr('src');
  761. }
  762. else
  763. {
  764. data[i] = $(this).val();
  765. }
  766. });
  767. store.set(this.save_key, data.join('|||'));
  768. //console.info(data);
  769. },
  770. recover : function()
  771. {
  772. if(confirm('确定恢复上次保存的数据吗?'))
  773. {
  774. var data = store.get(this.save_key).split('|||');
  775. if(data)
  776. {
  777. var value = $(".update_value");
  778. for(var k in data)
  779. {
  780. var e = value.eq(k);
  781. if(e.attr('update_type') == 'checked')
  782. {
  783. if(data[k] == 'true')
  784. {
  785. e.get(0).checked = true;
  786. }
  787. else
  788. {
  789. e.get(0).checked = false;
  790. }
  791. }
  792. else if(e.attr('update_type') == 'html')
  793. {
  794. e.html(data[k]);
  795. }
  796. else if(e.attr('update_type') == 'src')
  797. {
  798. e.attr('src', data[k]);
  799. }
  800. else
  801. {
  802. if(e.attr('id'))
  803. {
  804. var id = e.attr('id');
  805. if(typeof(editors[id]) != "undefined")
  806. {
  807. editors[id].setContent(data[k]);
  808. }
  809. }
  810. e.val(data[k]);
  811. }
  812. }
  813. store.set(this.save_key, '');
  814. this.check();
  815. }
  816. }
  817. },
  818. check : function()
  819. {
  820. var data = store.get(this.save_key);
  821. var self = this;
  822. if(data)
  823. {
  824. $(".maze_save").unbind('click').bind('click', function()
  825. {
  826. self.recover();
  827. }).show();
  828. }
  829. else
  830. {
  831. $(".maze_save").hide();
  832. self.auto = setInterval(function(){self.save()}, 3000);
  833. }
  834. },
  835. del : function()
  836. {
  837. var self = this;
  838. if($(".maze_form_delete").length)
  839. {
  840. $('.maze_form_delete').each(function()
  841. {
  842. $(this).unbind('click').bind('click', function()
  843. {
  844. var parent = $(this).parent();
  845. var id = parent.attr('id');
  846. var index = parseInt($('#tab-' + id).attr('toggle_id'));
  847. var key = $('#tab-' + id).attr('toggle_key');
  848. if(index <= 1 && self.index[key] <= index)
  849. {
  850. }
  851. else if(index <= 1 && self.index[key] > index)
  852. {
  853. index = index+1;
  854. $("#tab-"+key+"-child-" + index).click();
  855. }
  856. else
  857. {
  858. index = index-1;
  859. $("#tab-"+key+"-child-" + index).click();
  860. };
  861. $('#tab-' + id).parent().remove();
  862. parent.remove();
  863. })
  864. })
  865. }
  866. },
  867. append : function(e)
  868. {
  869. var self = this;
  870. var key = e.attr('toggle_key');
  871. var child = '.maze_'+key+'_child';
  872. if(typeof(self.index[key]) == "undefined")
  873. {
  874. self.index[key] = 0;
  875. }
  876. if(self.index[key] <= 0)
  877. {
  878. self.index[key] = $(child).length;
  879. }
  880. if(self.index[key] > 10)
  881. {
  882. alert('最多只能增加10条');
  883. return;
  884. }
  885. var p = e.parent();
  886. var id = key + '-child-' + self.index[key];
  887. var name = '第' + (self.index[key]) + '条';
  888. 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>');
  889. var e = e.parent().parent();
  890. var n = e.next();
  891. var p = e.parent();
  892. var content = n.html();
  893. content = content.replaceAll('_c_', '_c_' + self.index[key] + '_i_');
  894. content = '<div id="'+id+'" style="display:none;" class="'+n.attr('class')+' maze_form_add_child">' + content + '</div>';
  895. p.append(content);
  896. self.del();
  897. //$("html,body").animate({scrollTop:$('.maze_form_add_child').eq(this.appendIndex).offset().top},500);
  898. self.index[key]++;
  899. image();
  900. loadShow();
  901. autocomplete();
  902. change();
  903. },
  904. add : function(e)
  905. {
  906. var self = this;
  907. var p = e.parent();
  908. var id = 'data-' + this.addIndex;
  909. var name = '新增数据-' + (this.addIndex-1);
  910. p.before('<li><a href="#'+id+'" data-toggle="tab">'+name+'</a></li>');
  911. var content = $("#myTabContent").find('.tab-pane').eq(0).html();
  912. content = content.replaceAll('update_', 'update_' + this.addIndex + '__');
  913. content = '<div class="tab-pane fade" id="'+id+'">' + content + '</div>';
  914. $("#myTabContent").append(content);
  915. $('#update_' + this.addIndex + '__where_id').val('-1');
  916. this.addIndex++;
  917. }
  918. }
  919. String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) {
  920. if (!RegExp.prototype.isPrototypeOf(reallyDo)) {
  921. return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi": "g")), replaceWith);
  922. } else {
  923. return this.replace(reallyDo, replaceWith);
  924. }
  925. }
  926. Array.prototype.remove = function(val) {
  927. var index = -1;
  928. for(var i = 0; i < this.length; i++)
  929. {
  930. if(this[i] == val)
  931. {
  932. index = i;
  933. }
  934. }
  935. if (index > -1) {
  936. this.splice(index, 1);
  937. }
  938. };