From: rmccabe@sourceware.org <rmccabe@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] conga/luci/homebase homebase_common.js
Date: 30 Jun 2006 17:45:59 -0000 [thread overview]
Message-ID: <20060630174559.10123.qmail@sourceware.org> (raw)
CVSROOT: /cvs/cluster
Module name: conga
Changes by: rmccabe at sourceware.org 2006-06-30 17:45:59
Added files:
luci/homebase : homebase_common.js
Log message:
move common javascript into its own file
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/homebase/homebase_common.js.diff?cvsroot=cluster&r1=NONE&r2=1.1
/cvs/cluster/conga/luci/homebase/homebase_common.js,v --> standard output
revision 1.1
--- conga/luci/homebase/homebase_common.js
+++ - 2006-06-30 17:45:59.417970000 +0000
@@ -0,0 +1,196 @@
+function error_dialog(errors) {
+ if (!errors || errors.length < 1)
+ return (null);
+ alert('The following errors were found:\n\n' + errors.join('\n'));
+ return (-1);
+}
+
+function str_is_blank(str) {
+ return (!str || !str.replace(/\s/g, ''));
+}
+
+function str_is_valid(str, valid_regex_str) {
+ if (!str || !valid_regex_str)
+ return (null);
+ var re = eval(valid_regex_str);
+ var invalid = str.replace(re, '');
+ if (!invalid)
+ return (null);
+ return (invalid);
+}
+
+function checkAllBoxes(str, val) {
+ var i = 0;
+ var element;
+ while ((element = document.getElementById(str + i++)))
+ element.checked = val;
+}
+
+function checkChildren(parent_cont, parent_input) {
+ if (!parent_cont || !parent_input)
+ return
+ parent = document.getElementById(parent_cont);
+ children = parent.getElementsByTagName('input')
+ for (var i = 0 ; i < children.length ; i++) {
+ if (children[i] == parent_input)
+ continue;
+ if (children[i].type == 'checkbox')
+ children[i].checked = parent_input.checked;
+ }
+}
+
+function hide_element(id) {
+ var elem = document.getElementById(id);
+ if (elem)
+ elem.style['visibility'] = 'hidden';
+}
+
+function isValidHost(str) {
+ var i = str.split('.');
+
+ if (i.length == 1)
+ return ('Hostnames must be fully qualified.');
+
+ if (i.length == 4 && !isNaN(parseInt(i[3]))) {
+ var o1 = parseInt(i[0]);
+ var o2 = parseInt(i[1]);
+ var o3 = parseInt(i[2]);
+ var o4 = parseInt(i[3]);
+
+ if (isNaN(o1) || isNaN(o2) || isNaN(o3) ||
+ ((o1 & 0xff) != o1) ||
+ ((o2 & 0xff) != o2) ||
+ ((o3 & 0xff) != o3) ||
+ ((o4 & 0xff) != o4))
+ {
+ return ('Invalid IP Address.');
+ }
+
+ return (null);
+ }
+
+ if (!isNaN(parseInt(i[i.length - 1])))
+ return ('Invalid IP Address.');
+
+ if (!str.match(/^[0-9A-Za-z][0-9A-Za-z.-]*$/))
+ return ('Hostnames can contain only alphanumeric characters and hyphens.');
+
+ return (null);
+}
+
+function allPasswdsSame(form) {
+ var cb = document.getElementById('allSameCheckBox');
+ if (!cb)
+ return (-1);
+ var num_systems = form.numStorage.value;
+
+ var state = cb.checked;
+ var passwd = document.getElementById('__SYSTEM0:Passwd').value;
+ if (!passwd || !state)
+ passwd = '';
+
+ for (var i = 1 ; i < num_systems ; i++) {
+ var element = document.getElementById('__SYSTEM' + i + ':Passwd')
+ if (element) {
+ element.value = passwd;
+ element.disabled = state;
+ }
+ }
+}
+
+function pwd0Change(form) {
+ var element = document.getElementById('allSameCheckBox');
+ if (element && element.checked)
+ allPasswdsSame(form);
+}
+
+function addSystem(form) {
+ var sltab = document.getElementById('systemsTable');
+ if (!sltab)
+ return;
+ var num_systems = form.numStorage.value;
+
+ var newsys = document.createElement('input');
+ newsys.setAttribute('style', 'padding:.20em !important;width:200px;');
+ newsys.setAttribute('name', '__SYSTEM' + num_systems + ':Addr');
+ newsys.setAttribute('id', '__SYSTEM' + num_systems + ':Addr');
+ newsys.setAttribute('type', 'text');
+ newsys.setAttribute('value', '');
+
+ var newsysp = document.createElement('input');
+ newsysp.setAttribute('style', 'padding:.20em !important;width:160px;');
+ newsysp.setAttribute('name', '__SYSTEM' + num_systems + ':Passwd');
+ newsysp.setAttribute('id', '__SYSTEM' + num_systems + ':Passwd');
+ newsysp.setAttribute('type', 'password');
+ newsysp.setAttribute('value', '');
+
+ var allSameCB = document.getElementById('allSameCheckBox');
+ if (allSameCB && allSameCB.checked) {
+ newsysp.setAttribute('value', document.getElementById('__SYSTEM0:Passwd').value);
+ newsysp.setAttribute('disabled', true);
+ }
+
+ var newrow = document.createElement('tr');
+ var hcol = document.createElement('td')
+ hcol.setAttribute('style', 'margin: 0em;padding: 0em 1em .33em 0em;background: #dee7ec;padding-left: .5em;text-align: left;');
+ var pcol = document.createElement('td')
+ pcol.setAttribute('style', 'margin: 0em;padding: 0em 1em .33em 0em;background: #dee7ec;padding-left: .5em;text-align: left;');
+
+ hcol.appendChild(newsys)
+ pcol.appendChild(newsysp)
+ newrow.appendChild(hcol)
+ newrow.appendChild(pcol)
+ sltab.appendChild(newrow)
+
+ form.numStorage.value = ++num_systems;
+ if (num_systems == 2) {
+ var temp = document.getElementById('allSameDiv');
+ temp.style.visibility = 'visible';
+ temp = document.getElementById('allSameCheckBox');
+ temp.style.visibility = 'visible';
+ }
+}
+
+function validate_systems(form, errors) {
+ var allSameCB = document.getElementById('allSameCheckBox');
+ var added_storage = new Array();
+ var num_systems = form.numStorage.value;
+
+ for (var i = 0 ; i < num_systems ; i++) {
+ var element = document.getElementById('__SYSTEM' + i + ':Addr');
+
+ if (!element)
+ continue;
+
+ var pwdElem = document.getElementById('__SYSTEM' + i + ':Passwd');
+ if (!element.value) {
+ if (pwdElem.value) {
+ if (!allSameCB.checked) {
+ errors.push('You entered a password, but no hostname for system ' + (i + 1));
+ continue;
+ } else
+ pwdElem.value = '';
+ }
+
+ continue;
+ } else if (!pwdElem || !pwdElem.value)
+ errors.push('No password was given for \"' + element.value + '\"');
+ else if (str_is_blank(pwdElem.value))
+ errors.push('The password entered for \"' + element.value + '\" is blank.');
+
+ if (str_is_blank(element.value)) {
+ errors.push('You entered a blank hostname for system ' + (i + 1));
+ element.value = '';
+ } else {
+ var errmsg;
+ if ((errmsg = isValidHost(element.value)))
+ errors.push('\"' + element.value + '\" is not a valid hostname: ' + errmsg);
+ else {
+ pwdElem.disabled = false;
+ added_storage.push(element.value);
+ }
+ }
+ }
+
+ return (added_storage);
+}
next reply other threads:[~2006-06-30 17:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-06-30 17:45 rmccabe [this message]
-- strict thread matches above, loose matches on Subject: below --
2006-08-16 22:59 [Cluster-devel] conga/luci/homebase homebase_common.js rmccabe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060630174559.10123.qmail@sourceware.org \
--to=rmccabe@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.