mirror of
https://gitverse.ru/kpa39l/yaru.nixg.ru.git
synced 2026-09-29 18:05:05 +00:00
Initial commit: проект документации YARU
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
Friends.FriendsList = new function() {
|
||||
this.createFromTag = function(element) {
|
||||
new Friends.FriendsList.Constructor(element);
|
||||
};
|
||||
};
|
||||
|
||||
Friends.FriendsList.Constructor = function(element) {
|
||||
/** control container. */
|
||||
this.control = element;
|
||||
|
||||
/**
|
||||
* Чекбоксы. Если чекбокс выбран, то над этим пользователей будет
|
||||
* производиться действие.
|
||||
*/
|
||||
this.checkboxes = 0;
|
||||
|
||||
/** Кнопки "Сохранить". */
|
||||
this.submits = 0;
|
||||
|
||||
/** Начальные тексты НА кнопках "Сохранить" */
|
||||
this.submitsInitial = 0;
|
||||
|
||||
/** Тексты справа от кнопок "Сохранить". */
|
||||
this.submitTexts = 0;
|
||||
|
||||
/** Начальные тексты справа от кнопок "Сохранить". */
|
||||
this.submitTextsInitial = 0;
|
||||
|
||||
/** Количество отмеченых чекбоксов. */
|
||||
this.checked = 0;
|
||||
|
||||
/** Это страница регистрации? */
|
||||
this.isRegPage = 0;
|
||||
|
||||
this.init();
|
||||
};
|
||||
|
||||
Friends.FriendsList.Constructor.prototype = new function() {
|
||||
//public
|
||||
this.checkAll = function(_checkbox) {
|
||||
var checked = _checkbox.checked;
|
||||
this.checked = checked ? 0 : this.checkboxes.length;
|
||||
for (var i = 0, l = this.checkboxes.length; i < l; i++)
|
||||
this.check(this.checkboxes[i], checked);
|
||||
};
|
||||
|
||||
this.check = function(_checkbox, _checked) {
|
||||
var row = _checkbox.parentNode.parentNode;
|
||||
|
||||
var checked;
|
||||
if (_checked != -1 && !_checkbox.disabled){
|
||||
checked = _checkbox.checked = _checked;
|
||||
} else {
|
||||
checked = !y5.Classes.test(row, "checked");
|
||||
}
|
||||
|
||||
this.checkIt(row, checked);
|
||||
|
||||
var cell = y5.Dom.getDescendant(row, 'td', 'mutually'); //y5.cssQuery("td.mutually", row)[0];
|
||||
if (cell)
|
||||
y5.Classes.assign(cell, "mutually-checked", checked);
|
||||
|
||||
this.disable();
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
//private
|
||||
this.checkIt = function(_row, _checked) {
|
||||
if (_checked)
|
||||
{
|
||||
this.checked++;
|
||||
addClass(_row, "checked");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.checked--;
|
||||
delClass(_row, "checked");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//TODO:may be we should rename this function - since its toggles state, not just disabling
|
||||
//TODO:write this in russian
|
||||
this.disable = function() {
|
||||
var _this = this;
|
||||
if (this.checked == 0)
|
||||
{
|
||||
if (this.isRegPage)
|
||||
{
|
||||
this.submits.forEach(function(s, i) { s.disabled = false});
|
||||
}
|
||||
this.submits.forEach(function(s, i) { s.value = _this.submitsInitial[i] });
|
||||
this.submitTexts.forEach(function(s, i) {
|
||||
s.innerHTML = _this.submitTextsInitial[i];
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
var submitTextsNew = y5.Strings.plural(this.checked,
|
||||
["пользователь", "пользователя", "пользователей"]);
|
||||
this.submitTexts.forEach(function(s, i) {
|
||||
s.innerHTML = submitTextsNew;
|
||||
});
|
||||
|
||||
if (!this.isRegPage)
|
||||
{
|
||||
this.submits.forEach(function(s, i) { s.disabled = false });
|
||||
}
|
||||
else
|
||||
{
|
||||
this.submits.forEach(function(s, i) { s.value = 'Добавить в друзья' });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//constructor
|
||||
this.init = function() {
|
||||
var checkAllInput = y5.Dom.getDescendant(this.control, 'input', 'all');
|
||||
|
||||
if (checkAllInput) {
|
||||
checkAllInput.onclick = associateEventWithObject(this, "checkAll");
|
||||
}
|
||||
|
||||
this.checkboxes = getByTagName("input", getByTagName("tbody", this.control)[0]);
|
||||
for (var i = 0, l = this.checkboxes.length; i < l; i++) {
|
||||
this.checkboxes[i].onclick = associateEventWithObject(this, "check", -1);
|
||||
}
|
||||
|
||||
this.submits = y5.cssQuery("div.b-submit input[type='submit']", this.control.parentNode);
|
||||
this.submitsInitial = this.submits.map(function(s) { return s.value });
|
||||
|
||||
this.submitTexts = y5.cssQuery('div.b-submit p span', this.control.parentNode);
|
||||
this.submitTextsInitial = this.submits.map(function(s) { return s.innerHTML });
|
||||
|
||||
this.isRegPage = y5.Dom.getDescendants(document, 'table', 'b-page-reg').length;
|
||||
|
||||
this.disable();
|
||||
};
|
||||
}
|
||||
|
||||
y5.require(['cssQuery', 'Dom', 'Strings'], function() {y5.loaded('{Friends}.FriendsList')});
|
||||
|
||||
Reference in New Issue
Block a user