Early album draft

This commit is contained in:
2015-09-30 00:46:54 +08:00
parent be4d5c6ce2
commit 3e8e6362b2
8 changed files with 376 additions and 135 deletions
+98 -87
View File
@@ -1,7 +1,7 @@
(function(){
var ns = __namespace( "Astro.Blog.Components" );
/** @type {System.utils.EventKey} */
/** @type {System.utils.IKey} */
var IKey = __import( "System.utils.IKey" );
/** @type {Dandelion} */
var Dand = __import( "Dandelion" );
@@ -22,110 +22,121 @@
{
if( !config ) throw new Error( "config is not defined" );
// TODO: Make a trigger for downloading from server
var stage = Dand.id( id )
var stage = Dand.id( id );
this.id = id;
this.hash = hash;
this.type = IDOMElement( stage ).getDAttribute( "type" );
, applyStructure = function( obj )
{
// remove loading bubbles
while( stage.hasChildNodes() ) stage.removeChild(stage.firstChild);
if(!( this.type == "default" || this.type == null )) return this;
if( stage.getAttribute( "noauto" ) != null ) return this;
/** @type {_AstJson_.SiteFile} */
var finfo = JSON.parse( obj ).file;
var applyStructure = function( obj )
{
// remove loading bubbles
while( stage.hasChildNodes() ) stage.removeChild(stage.firstChild);
switch( finfo.type ) {
/** @type {_AstJson_.SiteFile} */
var finfo = JSON.parse( obj ).file;
case "image":
var node = Dand.wrap('img');
var k = new IKey( "src", null );
switch( finfo.type ) {
switch( IDOMElement(stage).getDAttribute('size') )
{
case "small":
k.keyValue = config.path.image.small + hash + '.jpg';
break;
case "medium":
k.keyValue = config.path.image.medium + hash + '.jpg';
break;
default: // large
k.keyValue = config.path.image.large + hash + '.jpg';
}
IDOMElement( node ).setAttribute( k );
case "image":
var node = Dand.wrap('img');
var k = new IKey( "src", null );
stage.appendChild(Dand.wrapne(
'a', node
switch( IDOMElement(stage).getDAttribute('size') )
{
case "small":
k.keyValue = config.path.image.small + hash + '.jpg';
break;
case "medium":
k.keyValue = config.path.image.medium + hash + '.jpg';
break;
default: // large
k.keyValue = config.path.image.large + hash + '.jpg';
}
IDOMElement( node ).setAttribute( k );
stage.appendChild(Dand.wrapne(
'a', node
, [
new IKey( 'href', config.f_host + finfo.src_location )
, new IKey( 'title', finfo.name )
, new IKey( 'target', '_blank' )
]
));
break;
case "audio":
// TODO
break;
default:
// create a form to post hash string to php
var hash_field = Dand.wrapna(
'input', [ new IKey( 'type', 'hidden' ), new IKey( 'name', 'hash' ) ]
)
, name_field = Dand.wrapna(
'input', [ new IKey( 'type', 'hidden' ), new IKey( 'name', 'name' ) ]
)
, link = Dand.wrapne(
'a', 'download', new IKey( 'href', config.path.download + finfo.name )
)
, form = Dand.wrap(
'form', null, 'sf_regular'
, [ name_field, hash_field ]
, [
new IKey( 'href', config.f_host + finfo.src_location )
, new IKey( 'title', finfo.name )
, new IKey( 'target', '_blank' )
new IKey('target', '_blank')
, new IKey('action', config.path.download + finfo.name)
, new IKey('method', 'POST')
]
));
)
;
break;
hash_field.value = hash;
name_field.value = finfo.name;
case "audio":
// TODO
break;
IDOMElement(link).addEventListener(
'Click'
, function(e) {
form.submit();
e.preventDefault();
return false;
}
);
default:
// create a form to post hash string to php
var hash_field = Dand.wrapna(
'input', [ new IKey( 'type', 'hidden' ), new IKey( 'name', 'hash' ) ]
)
, name_field = Dand.wrapna(
'input', [ new IKey( 'type', 'hidden' ), new IKey( 'name', 'name' ) ]
)
, link = Dand.wrapne(
'a', 'download', new IKey( 'href', config.path.download + finfo.name )
)
// file name
form.appendChild( Dand.wrapne( 'span', 'File: ' + finfo.name) );
, form = Dand.wrap(
'form', null, 'sf_regular'
, [ name_field, hash_field ]
, [
new IKey('target', '_blank')
, new IKey('action', config.path.download + finfo.name)
, new IKey('method', 'POST')
]
)
;
// download, submit button
form.appendChild( Dand.wrapne( 'sup', [ Dand.textNode(" ["), link, Dand.textNode("]") ] ) );
hash_field.value = hash;
name_field.value = finfo.name;
IDOMElement(link).addEventListener(
'Click'
, function(e) {
form.submit();
e.preventDefault();
return false;
}
);
// file name
form.appendChild( Dand.wrapne( 'span', 'File: ' + finfo.name) );
// download, submit button
form.appendChild( Dand.wrapne( 'sup', [ Dand.textNode(" ["), link, Dand.textNode("]") ] ) );
// hash
form.appendChild( Dand.wrapne( 'sup', Dand.wrape( 'MD5: ' + hash ) ) );
// date
form.appendChild( Dand.wrapne( 'sup', Dand.wrape( 'Date: ' + getSMStamp( new Date( finfo.date_created ) ) ) ) );
// hash
form.appendChild( Dand.wrapne( 'sup', Dand.wrape( 'MD5: ' + hash ) ) );
// date
form.appendChild( Dand.wrapne( 'sup', Dand.wrape( 'Date: ' + getSMStamp( new Date( finfo.date_created ) ) ) ) );
stage.appendChild(form);
}
stage.appendChild(form);
}
, loadFailed = function( obj )
{
while( stage.hasChildNodes() ) stage.removeChild( stage.firstChild );
stage.appendChild( Dand.wrapc( "sf_failed", Dand.textNode( "Error: Failed to get resources info" ) ) );
}
;
getData( config.path.info + hash, applyStructure, loadFailed );
};
var loadFailed = function( obj )
{
while( stage.hasChildNodes() ) stage.removeChild( stage.firstChild );
stage.appendChild( Dand.wrapc( "sf_failed", Dand.textNode( "Error: Failed to get resources info" ) ) );
};
this.loadInfo( applyStructure, loadFailed );
};
SiteFile.prototype.loadInfo = function( success, failed )
{
getData( config.path.info + this.hash, success, failed );
};
var init = function()