index.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. {template '_header'}
  2. <style type='text/css'>
  3. .dd-handle { height: 40px; line-height: 30px}
  4. .dd-list { width:860px;}
  5. </style>
  6. <div class="page-header">
  7. 当前位置:<span class="text-primary">魔方推荐</span>
  8. </div>
  9. <div class="page-content">
  10. <img src="{php echo SNAILFISH_STATIC . 'images/'}cube.jpg">
  11. <div class="alert alert-primary" style="margin-top: 10px;">提示:拖动改变位置,最多添加4个,请参照上图</div>
  12. <form action="" method="post" class="form-validate">
  13. <table class="table">
  14. <thead>
  15. <th style="width:60px;"></th>
  16. <th>图片</th>
  17. <th>链接</th>
  18. <th style="width: 60px;">操作</th>
  19. </thead>
  20. <tbody id="tbody">
  21. <?php foreach( $cubes as $i $cube ){ ?>
  22. <tr class="cube-item">
  23. <td>
  24. <a href="javascript:;" class="btn btn-default btn-sm btn-move"><i class="fa fa-arrows"></i></a>
  25. </td>
  26. <td>
  27. <div class="input-group img-item">
  28. <div class="input-group-addon" style="padding: 0 5px;">
  29. <img src="{:tomedia($cube['img'])}" style="height:20px;width:20px" onerror="this.src='/static/images/nopic.png'" />
  30. </div>
  31. <input type="text" class="form-control" name="cube_img[]" value="{$cube['img']}" readonly="readonly" />
  32. <div class="input-group-btn">
  33. <button type="button" class="btn btn-default btn-select-pic">选择图片</button>
  34. </div>
  35. </div>
  36. </td>
  37. <td>
  38. <div class="input-group form-group" style="margin: 0;">
  39. <input type="text" value="{$cube['url']}" class="form-control valid" name="cube_url[]" placeholder="" id="cubelink_{php echo $i+10000}">
  40. <span class="input-group-btn">
  41. <span data-input="#cubelink_{php echo $i+10000}" data-toggle="selectUrl" class="btn btn-default">选择链接</span>
  42. </span>
  43. <!-- <input type="text" value="{$cube['url']}" class="form-control valid" readonly="readonly"> -->
  44. </div>
  45. </td>
  46. <td>
  47. <button type="button" class="btn btn-danger btn-sm" onclick="removeCube(this)"><i class="fa fa-remove"></i></button>
  48. </td>
  49. </tr>
  50. <?php } ?>
  51. </tbody>
  52. <tfoot>
  53. <tr>
  54. <td colspan="4">
  55. <input type="submit" class="btn btn-primary" value="保存">
  56. <button type="button" class="btn btn-default" onclick="addCube()"><i class="fa fa-plus"></i> 添加魔方</button>
  57. </td>
  58. </tr>
  59. </tfoot>
  60. </table>
  61. </form>
  62. </div>
  63. <script language='javascript'>
  64. $(function () {
  65. bindEvents();
  66. })
  67. function removeCube(obj){
  68. $(obj).closest('.cube-item').remove();
  69. }
  70. function addCube(){
  71. if($('.cube-item').length>=4){
  72. tip.msgbox.err('最多添加4个魔方');
  73. return;
  74. }
  75. var timestamp=new Date().getTime();
  76. var html='<tr class="cube-item">';
  77. html+='<td><a href="javascript:;" class="btn btn-default btn-sm btn-move"><i class="fa fa-arrows"></i></a></td>';
  78. html+='<td>';
  79. html+='<div class="input-group img-item">';
  80. html+='<div class="input-group-addon">';
  81. html+='<img src="" style="height:20px;width:20px" onerror="this.src=\'/static/images/nopic.png\'"/>';
  82. html+='</div>';
  83. html+='<input type="text" class="form-control" name="cube_img[]" />';
  84. html+='<div class="input-group-btn">';
  85. html+='<button type="button" class="btn btn-default btn-select-pic">选择图片</button>';
  86. html+='</div>';
  87. html+='</div>';
  88. html+='</td><td><div class="input-group form-group" style="margin: 0;">';
  89. html+='<input type="text" value="" class="form-control valid" name="cube_url[]" placeholder="" id="cubelink_'+timestamp+'">';
  90. html+='<span data-input="#cubelink_'+timestamp+'" data-toggle="selectUrl" class="input-group-addon btn btn-default">选择链接</span></div>'
  91. html+='</td><td><button type="button" class="btn btn-danger btn-sm" onclick="removeCube(this)"><i class="fa fa-remove"></i></button>';
  92. html+='</td>';
  93. html+='</tr>';
  94. $('#tbody').append(html);
  95. bindEvents();
  96. }
  97. function bindEvents() {
  98. require(['jquery', 'util'], function ($, util) {
  99. $('.btn-select-pic').unbind('click').click(function () {
  100. var imgitem = $(this).closest('.img-item');
  101. util.image('', function (data) {
  102. imgitem.find('img').attr('src', data['url']);
  103. imgitem.find('input').val(data['attachment']);
  104. });
  105. });
  106. });
  107. require(['jquery.ui'] ,function(){
  108. $("#tbody").sortable({handle: '.btn-move'});
  109. })
  110. }
  111. myrequire(['jquery.nestable'], function () {
  112. $('#div_nestable').nestable({maxDepth: 1});
  113. $('.dd-item').addClass('full');
  114. $(".dd-handle a,.dd-handle div").mousedown(function (e) {
  115. e.stopPropagation();
  116. });
  117. $("#save_sort").click(function () {
  118. var json = window.JSON.stringify($('#div_nestable').nestable("serialize"));
  119. $(':input[name=datas]').val(json);
  120. })
  121. })
  122. </script>
  123. {template '_footer'}
  124. <!--OTEzNzAyMDIzNTAzMjQyOTE0-->