-
Notifications
You must be signed in to change notification settings - Fork 0
/
ActionHighlight.ts
62 lines (57 loc) · 1.73 KB
/
ActionHighlight.ts
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
export default class ActionHighlight extends ActionPlugin {
init(action:Action) {
var that = this;
this.action = action;
var form = action.form();
FormUtils.findVisibleFields(form).each(function() {
var $field, m, name, w;
$field = $(this);
name = $(this).attr("name");
if (name === "action") {
return;
}
if (!name) {
return;
}
name = name.replace(/\[\]/, '_');
m = $(".field-" + name + "-message").hide();
w = $(".field-" + name);
if (!w.length) {
$field.wrap("<div class=\"action-field field-" + name + "\"/>");
}
if (!m.length) {
$field.after("<div class=\"action-field-message field-" + name + "-message\"/>");
}
$(".action-field-message").hide();
});
$(action).bind('action.on_result', function(ev, resp) {
var msg, n, results, v, w;
that.clear();
results = [];
for (n in resp.validations) {
v = resp.validations[n];
w = that.form.find(".field-" + n);
msg = that.form.find(".field-" + n + "-message");
if (!v.valid) {
w.addClass("invalid");
results.push(msg.addClass("invalid").html(v.message).fadeIn("slow"));
} else {
w.addClass("valid");
results.push(msg.addClass("valid").html(v.message).fadeIn("slow"));
}
}
return results;
});
}
clear() {
var that = this;
var form = this.form();
FormUtils.findVisibleFields(form).each(function() {
var el, n;
el = $(this);
n = el.attr("name");
form.find(".field-" + n).removeClass("invalid valid");
form.find(".field-" + n + "-message").removeClass("invalid valid").html("").hide();
});
}
}