forked from colaghost/task_list
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbehaviors.js
145 lines (142 loc) · 4.53 KB
/
behaviors.js
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
var rules = {
// Rich Text Editors
'textarea.richtext': function(elt) {
new Control.RTE(elt, 'js/controls/rte/images', { fileLister: listUserFiles });
},
'input.datepicker': function(elt) {
new Control.DatePicker(elt, { icon: 'images/calendar.png' });
},
'input.timepicker': function(elt) {
new Control.DatePicker(elt, { icon: 'images/clock.png', datePicker: false, timePicker: true });
},
'input.datetimepicker': function(elt) {
new Control.DatePicker(elt, { icon: 'images/calendar.png', timePicker: true, timePickerAdjacent: true, use24hrs: true });
},
'input.datetimepicker_es': function(elt) {
new Control.DatePicker(elt, { icon: 'images/calendar.png', locale:'es_AR', timePicker: true });
},
'input.colorpicker': function(elt) {
new Control.ColorPicker(elt);
},
'input.filechooser': function(elt) {
new Control.FileChooser(elt, listUserFiles, {
icon: '/js/controls/filechooser/filechooser.png',
parentImage: '/js/controls/filechooser/parent.gif',
fileImage: '/js/controls/filechooser/file.gif',
directoryImage: '/js/controls/filechooser/directory.gif'
});
},
'.rating_bar': function(elt) {
var code = elt.id.replace(/rating_/, '');
new Control.RatingBar(elt, {
starClass: 'rating_star',
onClass: 'rating_on',
hoverClass: 'rating_hover',
halfClass: 'rating_half',
onclick: rateItem(code)
});
},
'.tabcontrol': function(elt) {
new Control.TabStrip(elt, {
activeClass: 'active',
hoverClass: 'hover',
disabledClass: 'disabled',
disabled: null
});
},
'.treeselect': function(elt) {
new TreeSelect(elt);
},
'#livegrid': function(elt) {
new Control.LiveGrid(elt, 10, 100, getData, {
prefetchBuffer: 'active',
selectable: true,
rowIdPrefix: 'result_',
onrowopen: openRows,
onrowselect: selectRows,
onscroll: scrollRows,
sortHeader: 'livegrid_header',
sortField: 'name',
sortDir: 'asc',
sortAscendImg: '/js/controls/livegrid/sort_asc.png',
sortDescendImg: '/js/controls/livegrid/sort_desc.png',
imageWidth: 9,
imageHeight: 9
});
},
'.treelist': function (elt) {
new Control.TreeList(elt, {
topOffset: 5,
collapseIcon: '/js/controls/treelist/down_arrow_outline.gif',
collapseIconHover: '/js/controls/treelist/down_arrow_filled.gif',
expandIcon: '/js/controls/treelist/right_arrow_outline.gif',
expandIconHover: '/js/controls/treelist/right_arrow_filled.gif'
});
}
};
Behaviour.register(rules);
function listUserFiles(directory, callback) {
new Ajax.Request('/software/js/fileaccess.php', {
parameters: 'a=listdir&d=' + (directory || ''),
onComplete: function(transport) {
try {
callback(eval('(' + transport.responseText + ')'));
} catch(e) {
callback({status:'error'});
}
}
});
}
function getData(offset, limit, sortField, sortDir, callback) {
new Ajax.Request('/software/js/getData.php', {
parameters: {
'offset': offset,
'limit': limit,
'sort': sortField,
'dir': sortDir
},
onComplete: function(transport) {
try {
callback(eval('(' + transport.responseText + ')'));
} catch (e) {
alert(e.message);
}
}
});
}
function selectRows(e, selector) {
var selected = selector.selectedRows();
var desc = selected.length ? selected.join(', ') : 'None';
$('livegrid_selected_label').innerHTML = 'Selected rows: ' + desc;
}
function openRows(e, selector) {
alert('Open row event: ' + selector.selectedRows().join(', '));
}
function scrollRows(start, count, total) {
$('livegrid_label').innerHTML = 'Viewing '+(start+1)+' to '+(start+count)+' of '+total+' results';
}
function rateItem(code) {
return function(ratingbar) {
var rating = ratingbar.rating;
ratingbar.setLoading(true);
new Ajax.Request('/ratings/rate.php', {
parameters: {'m': 'rpc', 'r': rating, 'c': code},
onSuccess: function(transport) {
ratingbar.setLoading(false);
try {
var response = eval('(' + transport.responseText + ')');
ratingbar.rating = response.rating;
ratingbar.resetRating();
$('rating_'+code+'_average').innerHTML = response.rating;
$('rating_'+code+'_votes').innerHTML = response.votes;
} catch(e) {
alert(e.message);
}
},
onFailure: function(transport) {
ratingbar.setLoading(false);
ratingbar.resetRating();
}
});
}
}