123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534 |
- if (typeof QFAMS === "undefined" || !QFAMS) {
-
- var QFAMS = {};
- }
- QFAMS.env = QFAMS.env || {
-
- persistantSelection: false,
-
- persistantMove: true
- };
- QFAMS.updateCounter = function (c, v) {
- var i;
- var nodeText = null;
- if (c !== null) {
-
- if (c.childNodes) {
- for (i = 0; i < c.childNodes.length; i++) {
- c.removeChild(c.childNodes[i]);
- }
- }
-
- nodeText = document.createTextNode(v);
- c.appendChild(nodeText);
- }
- };
- QFAMS.updateLiveCounter = function () {
- var lbl = this.parentNode;
- var selectedCount = 0;
-
- var div = lbl.parentNode;
- var inputs = div.getElementsByTagName('input');
- for (var i = 0; i < inputs.length; i++) {
- if (inputs[i].checked == 1) {
- selectedCount++;
- }
- }
- var e = div.id;
- var qfamsName = e.substring(e.indexOf('_', 0) + 1, e.length);
-
- var span = document.getElementById(qfamsName + '_selected');
- QFAMS.updateCounter(span, selectedCount + '/' + inputs.length);
- };
- QFAMS.editSelection = function (qfamsName, selectMode) {
- if (selectMode !== 0 && selectMode !== 1 && selectMode !== 2) {
- return;
- }
- var selectedCount = 0;
-
- var ams = document.getElementById('qfams_' + qfamsName);
- var inputs = ams.getElementsByTagName('input');
-
- for (var i = 0; i < inputs.length; i++) {
- if (selectMode === 2) {
- if (inputs[i].checked == 0) {
- inputs[i].checked = 1;
- } else if (inputs[i].checked == 1) {
- inputs[i].checked = 0;
- }
- } else {
- inputs[i].checked = selectMode;
- }
- if (inputs[i].checked == 1) {
- selectedCount++;
- }
- }
-
- var span = document.getElementById(qfamsName + '_selected');
- QFAMS.updateCounter(span, selectedCount + '/' + inputs.length);
- };
- QFAMS.moveSelection = function (qfamsName, selectLeft, selectRight, selectHidden, action, arrange) {
- var isIE = false;
- var source = null;
- var target = null;
- var option;
- var c = null;
- var s = null;
- var i;
- var maxFrom, maxTo;
- if (action === 'add' || action === 'all' || action === 'toggle') {
- source = selectLeft;
- target = selectRight;
- } else {
- source = selectRight;
- target = selectLeft;
- }
-
- if (source.selectedIndex === -1 && (action === 'add' || action === 'remove')) {
- return;
- }
- maxFrom = source.options.length;
- maxTo = target.options.length;
-
- if (maxTo > 0 && target.options[0].value === "") {
- target.removeAttribute("disabled");
- target.options[0] = null;
- }
-
- for (i = (maxFrom - 1); i >= 0; i--) {
- if (action === 'all' || action === 'none' || action === 'toggle' || source.options[i].selected === true) {
- if (source.options[i].disabled === false) {
- if (isIE) {
- option = source.options[i].removeNode(true);
- option.selected = QFAMS.env.persistantSelection;
- target.appendChild(option);
- } else {
- option = source.options[i].cloneNode(true);
- option.selected = QFAMS.env.persistantSelection;
- target.options[target.options.length] = option;
- }
- }
- }
- }
-
- if (!isIE) {
- for (i = (maxFrom - 1); i >= 0; i--) {
- if (action === 'all' || action === 'none' || action === 'toggle' || source.options[i].selected === true) {
- if (source.options[i].disabled === false) {
- source.options[i] = null;
- }
- }
- }
- }
-
- if (action === 'toggle') {
- for (i = (maxTo - 1); i >= 0; i--) {
- if (target.options[i].disabled === false) {
- if (isIE) {
- option = target.options[i].removeNode(true);
- option.selected = QFAMS.env.persistantSelection;
- source.appendChild(option);
- } else {
- option = target.options[i].cloneNode(true);
- option.selected = QFAMS.env.persistantSelection;
- source.options[source.options.length] = option;
- }
- }
- }
- if (!isIE) {
- for (i = (maxTo - 1); i >= 0; i--) {
- if (target.options[i].disabled === false) {
- target.options[i] = null;
- }
- }
- }
- }
-
- c = document.getElementById(qfamsName + '_unselected');
- s = document.getElementById(qfamsName + '-f');
- QFAMS.updateCounter(c, s.length);
-
- c = document.getElementById(qfamsName + '_selected');
- s = document.getElementById(qfamsName + '-t');
- QFAMS.updateCounter(c, s.length);
-
- if (arrange !== 'none') {
- QFAMS.sortList(target, QFAMS.compareText, arrange);
- }
-
-
- QFAMS.updateHidden(selectHidden, selectRight);
- };
- QFAMS.sortList = function (list, compareFunction, arrange)
- {
- var i;
- var options = new Array(list.options.length);
- for (i = 0; i < options.length; i++) {
- options[i] = new Option(list.options[i].text,
- list.options[i].value,
- list.options[i].defaultSelected,
- list.options[i].selected);
- }
- options.sort(compareFunction);
- if (arrange === 'desc') {
- options.reverse();
- }
- list.options.length = 0;
- for (i = 0; i < options.length; i++) {
- list.options[i] = options[i];
- }
- };
- QFAMS.compareText = function (option1, option2) {
- if (option1.text === option2.text) {
- return 0;
- }
- return option1.text < option2.text ? -1 : 1;
- };
- QFAMS.updateHidden = function (h, r) {
- var i;
- for (i = 0; i < h.length; i++) {
- h.options[i].selected = false;
- }
- for (i = 0; i < r.length; i++) {
- h.options[h.length] = new Option(r.options[i].text, r.options[i].value);
- h.options[h.length - 1].selected = true;
- }
- };
- QFAMS.moveUp = function (l, h) {
- var indice = l.selectedIndex;
- if (indice < 0) {
- return;
- }
- if (indice > 0) {
- QFAMS.moveSwap(l, indice, indice - 1);
- QFAMS.updateHidden(h, l);
- }
- };
- QFAMS.moveDown = function (l, h) {
- var indice = l.selectedIndex;
- if (indice < 0) {
- return;
- }
- if (indice < l.options.length - 1) {
- QFAMS.moveSwap(l, indice, indice + 1);
- QFAMS.updateHidden(h, l);
- }
- };
- QFAMS.moveTop = function (l, h) {
- var indice = l.selectedIndex;
- if (indice < 0) {
- return;
- }
- while (indice > 0) {
- QFAMS.moveSwap(l, indice, indice - 1);
- QFAMS.updateHidden(h, l);
- indice--;
- }
- };
- QFAMS.moveBottom = function (l, h) {
- var indice = l.selectedIndex;
- if (indice < 0) {
- return;
- }
- while (indice < l.options.length - 1) {
- QFAMS.moveSwap(l, indice, indice + 1);
- QFAMS.updateHidden(h, l);
- indice++;
- }
- };
- QFAMS.moveSwap = function (l, i, j) {
- var node;
- node = l.replaceChild(l.options[i], l.options[j]);
- if (i > j) {
- l.insertBefore(node, l.options[j].nextSibling);
- } else {
- l.insertBefore(node, l.options[i]);
- }
- if (QFAMS.env.persistantMove) {
- l.selectedIndex = j;
- } else {
- l.selectedIndex = -1;
- }
- };
- QFAMS.init = function (elm)
- {
- var e, i;
- for (e = 0; e < elm.length; e++) {
- var div = document.getElementById('qfams_' + elm[e]);
- if (div !== null) {
- var inputs = div.getElementsByTagName('input');
- if (inputs !== null) {
- for (i = 0; i < inputs.length; i++) {
- inputs[i].onclick = QFAMS.updateLiveCounter;
- }
- }
- }
- }
- };
- $(function() {
- $('.advmultiselect_checkbox').click(function() {
- var id = $(this).attr('id');
- var selectName = id + '-f';
- var selectId = selectName.replace('_select_all', '');
- var selectDestinationId = selectId.replace('-f', '-t');
- $('#'+selectDestinationId).prop("disabled", false);
- var checked = !$('#'+ id).is(':checked');
- if (!checked) {
- $('#users-f option').prop('selected', true);
- QFAMS.moveSelection('users', this.form.elements['users-f[]'], this.form.elements['users-t[]'], this.form.elements['users[]'], 'add', 'none');
- } else {
- $('#users-t option').prop('selected', true);
- QFAMS.moveSelection('users', this.form.elements['users-f[]'], this.form.elements['users-t[]'], this.form.elements['users[]'], 'remove', 'none');
- }
- });
- });
|