attr_values.html
3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!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>