<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>图片管理</title>
  <link rel="stylesheet" href="{url:@static/css/base.css}" />
  <link rel="stylesheet" href="{url:@static/css/admin.css}" />
  <link rel="stylesheet" href="{url:@static/css/font_icon.css}" />
<!--[if lte IE 7]><script src="{url:@static/css/fonts/lte-ie7.js}"></script><![endif]-->
  {echo:JS::import('jquery')}
  {echo:JS::import('form')}
  {echo:JS::import('dialog?skin=brief');}
  {echo:JS::import('dialogtools');}
  <script src="{url:@static/js/common.js}" charset="UTF-8" type="text/javascript"></script>
</head>
<body style="background:#fff;">
{echo:JS::import('validator');}
{echo:JS::import('form');}
{echo:JS::import('dialog?skin=brief');}
{echo:JS::import('dialogtools');}
<form class="form2" callback="formatValue" needsValidate="true">
<div class="alone_header">
      <button class="focus_button" id="addSpecButton" >添加属性值</button>
</div>
      <div class="alone_content">
      <table class="default" id="attr_values" style="margin-top:50px;">
        <tr><th width="400">属性值</th> <th width="200">操作</th></tr>
      </table>
      </div>
    <div class="alone_footer tc"><button class="focus_button">保存属性值</button><button class="button">关闭</button></div>
    </form>
<script type="text/javascript">
var form =  new Form();
form.setValue('parent_id','{$parent_id}');
form.setValue('type','{$type}');

$("#addSpecButton").on("click",function(){
    $("#attr_values").append('<tr> <td><input type="hidden" name="value_id[]" value="0"><input type="text" name="value[]" pattern="required" /></td> <td class="btn_min"><a href="javascript:;" class="icon-arrow-up-2">上升</a><a href="javascript:;" class="icon-arrow-down-2">下降</a><a href="javascript:;"  class="icon-remove-2">删除</a></td></tr>');
  bindEvent();
  return false;
})

bindEvent();
//操作按钮事件绑定
function bindEvent(){
  $(".icon-arrow-down-2").off();
  $(".icon-arrow-up-2").off();
  $(".icon-remove-2").off();
  $(".select_button").off();
  $(".icon-arrow-down-2").on("click",function(){
    var current_tr = $(this).parent().parent();
    current_tr.insertAfter(current_tr.next());
  });
    $(".icon-arrow-up-2").on("click",function(){
    var current_tr = $(this).parent().parent();
    if(current_tr.prev().prev().html()!=null)current_tr.insertBefore(current_tr.prev());
  });
    $(".icon-remove-2").on("click",function(){
      if($("input[name='value[]']").length>1)$(this).parent().parent().remove();
      else alert('至少要保留一个属性值');
    });
    $(".select_button").each(function(i){
      var num = i;
      $(this).on("click",function(){
      uploadFile(num);
      return false;
    });
    });
}

function formatValue(e){
  var attr_values = new Array();
  var num = 0;
  $("#attr_values tr").has("input").each(function(){
    var value = new Array();
    var id = $(this).find("input:eq(0)").val();
    var name = $(this).find("input:eq(1)").val();
    attr_values[num++] = id+':=:'+name;
  })
  if(e==null)parent.updAttrValue(attr_values);
  return false;
}
//alert(art.dialog.data('current_values'));
var current_value = art.dialog.data('current_value');
if(current_value!=""){
  var values = current_value.split(',');
  for(i in values){
    var id_name = values[i].split(":=:");
    $("#attr_values").append('<tr> <td><input type="hidden" name="value_id[]" value="'+id_name[0]+'"><input type="text" name="value[]" pattern="required" value="'+id_name[1]+'"/></td> <td class="btn_min"><a href="javascript:;" class="icon-arrow-up-2">上升</a><a href="javascript:;" class="icon-arrow-down-2">下降</a><a href="javascript:;"  class="icon-remove-2">删除</a></td></tr>');
    bindEvent();
  }
}

</script>
</body>
</html>