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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
var card_2_delete_id;
var card_detail_id;
$(document).ready(function(){
//不允许input框复制,减少验证粘帖的交互
$("input[type='text']").bind("paste", function(){
return false;
});
//副标题点大叉
$("#index_title_closed_icon").bind("click", function(){
var closeBtn = $(this);
var date = new Date();
var time = date.getTime();
$.ajax({ //数据库还是cookie,都可以,建议使用cookie,html中是否显示sub_title也由后端读取的cookie决定
type: 'get',
url: indicator_url + 'ajax/close_sub_title',
data: 'time='+time,
success: function(data){
if(data == 'success'){
closeBtn.parent().remove();
}
}
});
return false;
});
//卡片大叉删除交互
$(".card_delete_icon").hover(
function(){
$(this).removeClass("card_delete");
$(this).addClass("card_delete_hover");
},
function(){
$(this).removeClass("card_delete_hover");
$(this).addClass("card_delete");
}
);
$(".card_delete_icon").bind("click", function(){
card_2_delete_id = $(this).parent().attr("id").replace('index_card_', '');
});
//点击编辑icon
$(".small_edit_icon").bind("click", function(){
var this_edit_data_div = $(this).parent();
var this_select_date_div = this_edit_data_div.siblings(".select_date");
var this_refresh_data_div = this_edit_data_div.siblings(".refresh_data");
var this_last_edit_data_div = $(this).siblings(".last_edit_data");
var this_editing_data_div = this_edit_data_div.siblings(".editing_data");
var input_container = this_editing_data_div.children(".input_container");
var data_fir = this_last_edit_data_div.children(".data_fir").text();
var data_sec = this_last_edit_data_div.children(".data_sec").text();
input_container.children(".edit_input_main").val(parseInt(data_fir));
input_container.children(".edit_input_sub").val(parseInt(data_sec));
this_editing_data_div.show();
this_select_date_div.show();
this_edit_data_div.hide();
this_refresh_data_div.hide();
return false;
});
//点击指数+1 icon
$(".add_icon").bind("click", function(){
var this_edit_input_sub = $(this).closest(".editing_data").children(".input_container").children(".edit_input_sub");
var origin_value = parseInt(this_edit_input_sub.val());
this_edit_input_sub.val(origin_value+1);
return false;
});
//点击 指数-1 icon
$(".minus_icon").bind("click", function(){
var this_edit_input_sub = $(this).closest(".editing_data").children(".input_container").children(".edit_input_sub");
var origin_value = parseInt(this_edit_input_sub.val());
var after_value = origin_value-1;
if(after_value >= 0){
this_edit_input_sub.val(origin_value-1);
}
return false;
});
//编辑数据的底数验证:只允许两位小数,非空
$(".edit_input_main").bind("keyup", function(){
var val = $(this).val();
val = val.replace(/[^\d.]/g,"");//清除"数字"和"."以外的字符
val = val.replace(/^\./g,"");//验证第一个字符是数字而不是..
val = val.replace(/\.{2,}/g,".");//只保留第一个. 清除多余的
val = val.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
val = val.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');
$(this).val(val);
return false;
});
//编辑数据的指数验证:只允许整数
$(".edit_input_sub").bind("keyup", function(){
$(this).val($(this).val().replace(/[^\d]/g, ''));
return false;
});
//点击取消icon
$(".cancel_edit_icon").bind("click", function(){
var input_container = $(this).siblings(".input_container");
input_container.children(".edit_input_main").val('');
input_container.children(".edit_input_sub").val('');
var this_editing_data_div = $(this).parent();
this_editing_data_div.siblings(".edit_data").show();
this_editing_data_div.siblings(".refresh_data").show();
this_editing_data_div.hide();
this_editing_data_div.siblings(".select_date").hide();
return false;
});
//点击提交icon
$(".confirm_edit_icon").bind("click", function(){
var input_container = $(this).siblings(".input_container");
var data_input_fir = input_container.children(".edit_input_main");
var data_input_sec = input_container.children(".edit_input_sub");
var data_input_fir_val = data_input_fir.val();
var data_input_sec_val = data_input_sec.val();
if(data_input_fir_val == '' || data_input_fir_val == 0){
data_input_fir.addClass("error");
}else{
data_input_fir.removeClass("error");
}
if(data_input_sec_val == ''){
data_input_sec.addClass("error");
}else{
data_input_sec.removeClass("error");
}
if($(".error").length > 0){
return false;
}
//TODO ajax
data_input_fir.val('');
data_input_sec.val('');
var this_editing_data_div = $(this).parent();
var this_select_date_div = this_editing_data_div.siblings(".select_date");
var this_refresh_data_div = this_editing_data_div.siblings(".refresh_data");
var this_edit_data_div = this_editing_data_div.siblings(".edit_data");
var this_last_edit_div = this_edit_data_div.children(".last_edit_data");
this_last_edit_div.show();
this_last_edit_div.children(".data_fir").html(data_input_fir_val);
this_last_edit_div.children(".data_sec").html(data_input_sec_val);
this_editing_data_div.hide();
this_select_date_div.hide();
this_edit_data_div.show();
this_refresh_data_div.show();
return false;
});
//日期控件
$(".select_date>.datepicker").datepicker({
showOn: "both",
buttonImage: static_url + "plugins/datepicker/images/calendar.png",
buttonImageOnly: true
});
//时间范围控制(开始时间<结束时间)
$("#search_start_date").datepicker({
showOn: "both",
buttonImage: static_url + "plugins/datepicker/images/calendar.png",
buttonImageOnly: true,
onClose: function( selectedDate ) {
$("#search_end_date").datepicker("option", "minDate", selectedDate);
}
});
$("#search_end_date").datepicker({
onClose: function( selectedDate ) {
$("#search_start_date").datepicker("option", "maxDate", selectedDate);
}
});
});
function delete_card(){
var card = $("#index_card_"+card_2_delete_id);
card.nextAll().each(function(){
if($(this).hasClass("index_card_fir")){
$(this).removeClass("index_card_fir");
$(this).addClass("index_card_sec");
}else if($(this).hasClass("index_card_sec")){
$(this).removeClass("index_card_sec");
$(this).addClass("index_card_fir");
}
});
card.remove();
}
// vim: set ts=4 sw=4 tw=0 fenc=utf-8 ft=javascript: //
|