2009-01-23 18:03:39 +01:00
|
|
|
## -*- coding: utf-8 -*-
|
|
|
|
<%doc>
|
|
|
|
Helper JavaScript for the data input form.
|
2010-06-11 21:42:30 +02:00
|
|
|
Copyright © 2009, 2010 Jan Dittberner <jan@dittberner.info>
|
2009-01-23 18:03:39 +01:00
|
|
|
|
|
|
|
This file is part of DDPortfolio service.
|
|
|
|
|
|
|
|
DDPortfolio service is free software: you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Affero General Public License as
|
|
|
|
published by the Free Software Foundation, either version 3 of the
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
DDPortfolio service is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public
|
|
|
|
License along with this program. If not, see
|
|
|
|
<http://www.gnu.org/licenses/>.
|
|
|
|
</%doc>
|
|
|
|
|
2010-06-11 23:36:16 +02:00
|
|
|
var defaulthiddendivs = new Array(
|
2010-06-12 00:02:17 +02:00
|
|
|
'#namefield', '#gpgfpfield', '#usernamefield', '#nonddemailfield',
|
|
|
|
'#aliothusernamefield', '#wikihomepagefield', '#forumsidfield');
|
2010-06-11 23:36:16 +02:00
|
|
|
var maskedfielddivs = new Array(
|
|
|
|
'#namefield', '#gpgfpfield', '#usernamefield', '#nonddemailfield',
|
2010-06-12 00:02:17 +02:00
|
|
|
'#aliothusernamefield', '#wikihomepagefield', '#forumsidfield');
|
2010-06-11 23:36:16 +02:00
|
|
|
var allfielddivs = new Array(
|
|
|
|
'#namefield', '#gpgfpfield', '#usernamefield', '#nonddemailfield',
|
2010-06-12 00:02:17 +02:00
|
|
|
'#aliothusernamefield', '#wikihomepagefield', '#forumsidfield');
|
2010-06-11 23:36:16 +02:00
|
|
|
|
2009-01-23 18:03:39 +01:00
|
|
|
function updateFields(data, textStatus) {
|
2010-06-11 21:42:30 +02:00
|
|
|
if (data.type == 2) { // DD
|
2009-01-23 18:03:39 +01:00
|
|
|
$('#name').attr('value', data.name).attr('readonly', 'readonly');
|
|
|
|
$('#gpgfp').attr('value', data.gpgfp);
|
|
|
|
$('#username').attr('value', data.username).attr(
|
|
|
|
'readonly', 'readonly');
|
|
|
|
$('#nonddemail').attr('value', data.email).focus();
|
|
|
|
$('#aliothusername').attr('value', data.username);
|
2010-06-12 00:02:17 +02:00
|
|
|
$('#wikihomepage').attr('value', data.wikihomepage);
|
2009-01-23 18:03:39 +01:00
|
|
|
|
|
|
|
$('#namefield').show();
|
|
|
|
$('#gpgfpfield').show();
|
|
|
|
$('#usernamefield').show();
|
|
|
|
$('#nonddemailfield').show();
|
|
|
|
$('#aliothusernamefield').show();
|
2010-06-12 00:02:17 +02:00
|
|
|
$('#wikihomepagefield').show();
|
|
|
|
$('#forumsidfield').show();
|
2009-01-23 18:03:39 +01:00
|
|
|
|
|
|
|
$('#nonddemail').focus().select();
|
2010-06-11 21:42:30 +02:00
|
|
|
} else if (data.type == 1) { // DM
|
|
|
|
$('#name').attr('value', data.name).attr('readonly', 'readonly');
|
|
|
|
$('#gpgfp').attr('value', data.gpgfp);
|
|
|
|
$('#username').attr('value', '');
|
|
|
|
$('#nonddemail').attr('value', data.email).focus();
|
2010-06-12 00:02:17 +02:00
|
|
|
$('#wikihomepage').attr('value', data.wikihomepage);
|
2010-06-11 21:42:30 +02:00
|
|
|
|
|
|
|
$('#namefield').show();
|
|
|
|
$('#gpgfpfield').show();
|
|
|
|
$('#usernamefield').hide();
|
|
|
|
$('#nonddemailfield').hide();
|
|
|
|
$('#aliothusernamefield').show();
|
2010-06-12 00:02:17 +02:00
|
|
|
$('#wikihomepagefield').show();
|
|
|
|
$('#forumsidfield').show();
|
2010-06-11 21:42:30 +02:00
|
|
|
|
|
|
|
$('#aliothusername').focus().select();
|
2009-01-23 18:03:39 +01:00
|
|
|
} else {
|
|
|
|
$('#nonddemail').attr('value', data.email);
|
|
|
|
$('#name').removeAttr('readonly');
|
|
|
|
$('#username').removeAttr('readonly').attr('value', '');
|
|
|
|
$('#gpgfp').attr('value', '');
|
|
|
|
|
|
|
|
$('#usernamefield').hide();
|
|
|
|
$('#gpgfpfield').hide();
|
|
|
|
$('#nonddemailfield').hide();
|
|
|
|
$('#namefield').show();
|
|
|
|
$('#aliothusernamefield').show();
|
2010-06-12 00:02:17 +02:00
|
|
|
$('#wikihomepagefield').show();
|
|
|
|
$('#forumsidfield').show();
|
2009-01-23 18:03:39 +01:00
|
|
|
|
|
|
|
$('#name').focus().select();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-11 23:14:30 +02:00
|
|
|
function onChangeShowAll(event) {
|
2010-06-11 23:36:16 +02:00
|
|
|
if ($('#showall').attr('checked')) {
|
|
|
|
for (var fielddiv in allfielddivs) {
|
|
|
|
$(allfielddivs[fielddiv]).show();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (var fielddiv in maskedfielddivs) {
|
|
|
|
$(maskedfielddivs[fielddiv]).hide();
|
|
|
|
}
|
|
|
|
}
|
2010-06-11 23:14:30 +02:00
|
|
|
}
|
|
|
|
|
2009-01-23 18:03:39 +01:00
|
|
|
function onBlurEmail() {
|
2010-06-11 23:14:30 +02:00
|
|
|
if ($.trim($('#email').attr('value')).length > 0) {
|
|
|
|
$.ajax({
|
|
|
|
'url' : '${h.url_for(action='fetchdddata')}',
|
|
|
|
'data' : {'email' : $('#email').attr('value')},
|
|
|
|
'dataType' : 'json',
|
|
|
|
'success' : updateFields,
|
|
|
|
'error' : function(request, textStatus, errorThrown) {
|
|
|
|
$('#email').focus();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2009-01-23 18:03:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
2010-06-11 23:36:16 +02:00
|
|
|
for (var index in defaulthiddendivs) {
|
2010-06-12 00:02:17 +02:00
|
|
|
if (!$(defaulthiddendivs[index]).hasClass('witherrors')) {
|
|
|
|
$(defaulthiddendivs[index]).hide();
|
|
|
|
}
|
2010-06-11 23:36:16 +02:00
|
|
|
}
|
2009-01-23 18:03:39 +01:00
|
|
|
|
2010-06-11 23:40:00 +02:00
|
|
|
$('#showall').attr('checked', false).change(onChangeShowAll);
|
|
|
|
$('#showallfield').show();
|
2009-01-23 18:03:39 +01:00
|
|
|
$('#email').blur(onBlurEmail).focus();
|
|
|
|
});
|