botanjs/src/Astro/Blog/Layout/Login.js
raw ยท 2604 bytes
(function(){
var ns = __namespace( "Astro.Blog.Layout.Login" );
/** @type {System.Cycle} */
var Cycle = __import( "System.Cycle" );
/** @type {typeof System.utils.IKey} */
var IKey = __import( "System.utils.IKey" );
/** @type {typeof Components.MessageBox} */
var MessageBox = __import( "Components.MessageBox" );
/** @type {typeof Dandelion} */
var Dand = __import( "Dandelion" );
/** @type {Astro.Bootstrap} */
var Bootstrap = __import( "Astro.Bootstrap" );
/** @type {Astro.Blog.Config} */
var config = __import( "Astro.Blog.Config" );
// __import( "Dandelion.CSSReset" ); CSS_RESERVATION
// __import( "Dandelion.CSSAnimations" ); CSS_RESERVATION
/** @type {_AstConf_.Login} */
var conf = config.get( "Login" );
var sHeat = conf.sHeat || "";
var sTTR = conf.sTTR || 0;
var formAction = conf.formAct || "./";
var field_username = new IKey( "name", "username" );
var field_password = new IKey( "name", "password" );
var init = function ()
{
var username;
var sTTRe;
var form = Dand.wrapne("form"
, [
// Basic login and password fields
, Dand.wrapc("flsf", "Name:")
, username = Dand.wrapna("input", [ field_username, new IKey("type", "text") ] )
, Dand.wrapc("flsf", "Password:")
, Dand.wrapna("input", [ field_password, new IKey("type", "password") ] )
, sTTRe = Dand.wrap( "span", null, "sttr", PrintTTR( sTTR ) )
, Dand.wrapc( "msg", Dand.wrap("sub", null, sHeat.toLowerCase(), sHeat ) )
]
, [
// Form attributes
new IKey("action", formAction)
, new IKey("method", "POST")
]
);
if( 0 < sTTR )
{
Cycle.perma( "STTR", function()
{
if( 0 < sTTR -- ) sTTRe.innerHTML = PrintTTR( sTTR );
}, 1000 );
}
var mbox = new MessageBox( "Blog.Astro", form, "Login", false, submitForm.bind( form ) ).show();
username.focus();
// Handle enter button
mbox.onkeyup = function( _e )
{
if ( submitForm.bind( form )( _e.which == 13 ) )
{
document.body.removeChild( this );
}
};
};
var PrintTTR = function ( s )
{
if( s <= 0 ) return "";
return "You are locked for " + s + "s, further login attempts will result in time-reset until the lock is released";
};
var submitForm = function (bool) {
if ( bool )
{
if ( this[ field_username.keyValue ].value != ""
&& this[ field_password.keyValue ] != "" )
{
this.submit();
return true;
}
}
return false;
};
Bootstrap.regInit( init );
})();