edit.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <extend name="Public:base" />
  2. <block name="content">
  3. <div class="alert alert-danger hidden"><i class="fa fa-exclamation-circle"></i><span id="error"></span>
  4. <button type="button" class="close">&times;</button>
  5. </div>
  6. <div class="page-header">
  7. <h1>
  8. {$breadcrumb2}
  9. <small>
  10. <i class="icon-double-angle-right"></i>
  11. {$crumbs}
  12. </small>
  13. <button name="send" type="submit" style="float:right;" class="btn button btn-sm btn-primary">提交</button>
  14. </h1>
  15. </div>
  16. <div class="row">
  17. <div class="col-xs-12">
  18. <div class="form-horizontal">
  19. <notempty name="Think.get.id">
  20. <input name="id" type="hidden" value="{$Think.get.id}" />
  21. </notempty>
  22. <div class="form-group">
  23. <label class="col-sm-2 control-label"> * 选项名称 </label>
  24. <div class="col-sm-10">
  25. <div class="clearfix">
  26. <input name="name" id="name" class="col-xs-10 col-sm-5" value="{$option.name|default=''}" type="text">
  27. </div>
  28. </div>
  29. </div>
  30. <div class="form-group">
  31. <label class="col-sm-2 control-label"> * 类型 </label>
  32. <div class="col-sm-4">
  33. <select class="form-control" name="type">
  34. <option <?php if($option['type']=='select'){echo ' selected="selected"';} ?> value="select">下拉列表(单选)</option>
  35. <option <?php if($option['type']=='radio'){echo ' selected="selected"';} ?> value="radio">单选组</option>
  36. <option <?php if($option['type']=='checkbox'){echo ' selected="selected"';} ?> value="checkbox">多选组</option>
  37. </select>
  38. </div>
  39. </div>
  40. <table id="option-value" class="table table-striped table-bordered table-hover">
  41. <thead>
  42. <tr>
  43. <td class="text-left required">选项值:</td>
  44. <td class="text-left"> 排序:</td>
  45. <td></td>
  46. </tr>
  47. </thead>
  48. <tbody>
  49. <?php $option_value_row = 1; ?>
  50. <?php if(isset($option_values)){ ?>
  51. <?php foreach ($option_values as $option_value) { ?>
  52. <tr id="option-value-row<?php echo $option_value_row; ?>">
  53. <td class="text-left">
  54. <input type="text" name="option_value[<?php echo $option_value_row; ?>][name]" value="<?php echo $option_value['value_name']; ?>" />
  55. </td>
  56. <td class="text-right"><input type="text" name="option_value[<?php echo $option_value_row; ?>][sort_order]" value="<?php echo $option_value['value_sort_order']; ?>" class="form-control" /></td>
  57. <td class="text-left"><button type="button" onclick="$('#option-value-row<?php echo $option_value_row; ?>').remove();" data-toggle="tooltip" class="btn btn-danger"><i class="icon-trash"></i></button></td>
  58. </tr>
  59. <?php $option_value_row++; ?>
  60. <?php } ?>
  61. <?php } ?>
  62. </tbody>
  63. </table>
  64. <div>
  65. <a class="add_image btn btn-primary " onclick="addOptionValue();">添加选项值</a>
  66. </div>
  67. </div>
  68. </div>
  69. </div>
  70. </block>
  71. <block name="javascript">
  72. <script>
  73. var option_value_row = '<?php echo $option_value_row; ?>';
  74. function addOptionValue() {
  75. html = '<tr id="option-value-row' + option_value_row + '">';
  76. html += '<td class="text-left">';
  77. html += '<div><input type="text" name="option_value[' + option_value_row + '][name]" value="" class="form-control" />';
  78. html += '</div>';
  79. html += '</td>';
  80. html += ' <td class="text-right"><input type="text" name="option_value[' + option_value_row + '][sort_order]" value="' + option_value_row + '" class="form-control" /></td>';
  81. html += ' <td class="text-left"><button type="button" onclick="$(\'#option-value-row' + option_value_row + '\').remove();" data-toggle="tooltip" class="btn btn-danger"><i class="icon-trash"></i></button></td>';
  82. html += '</tr>';
  83. $('#option-value tbody').append(html);
  84. option_value_row++;
  85. }
  86. $('.button').click(function(){
  87. $.ajax({
  88. url: '{$action}',
  89. type: 'post',
  90. data: $('input[type=\'text\'],select,input[type=\'hidden\']'),
  91. dataType: 'json',
  92. beforeSend: function() {
  93. $('.button').attr('disabled', true);
  94. $('.button').after('<span class="wait">&nbsp;<img src="__IMG__/loading.gif" alt="" /></span>');
  95. },
  96. complete: function() {
  97. $('.button').attr('disabled', false);
  98. $('.wait').remove();
  99. },
  100. success: function(json) {
  101. $('.alert-danger').addClass('hidden');
  102. if (json['redirect']) {
  103. location = json['redirect']
  104. } else if (json['error']) {
  105. $('.alert-danger').removeClass('hidden');
  106. $('#error').text(json['error']);
  107. }
  108. },
  109. error: function(xhr, ajaxOptions, thrownError) {
  110. alert('修改失败');
  111. }
  112. });
  113. });
  114. $('.close').click(function(){
  115. $(this).parent().addClass('hidden');
  116. });
  117. </script>
  118. </block>