penguin/AstroJS

Javascript framework for my blog

botanjs/src/Astro/Blog/AstroEdit/SmartInput/CandidateAction/ArticleReference.js

raw ยท 1784 bytes

(function ()
{
	var ns = __namespace( "Astro.Blog.AstroEdit.SmartInput.CandidateAction" );

	/** @type {System.utils.IKey} */
	var IKey                             = __import( "System.utils.IKey" );
	/** @type {System.utils.DataKey} */
	var DataKey                          = __import( "System.utils.DataKey" );
	/** @type {Dandelion.IDOMElement} */
	var IDOMElement                      = __import( "Dandelion.IDOMElement" );
	/** @type {Dandelion} */
	var Dand                             = __import( "Dandelion" );
	/** @type {Astro.Blog.Config} */
	var Config                           = __import( "Astro.Blog.Config" );

	var getData                          = __import( "System.Net.getData" );
	var prettyDate                       = __import( "Astro.utils.Date.pretty" );

	/** @type {_AstConf_.AstroEdit} */
	var Conf = Config.get( "AstroEdit" );

	/** @type {Astro.Blog.AstroEdit.SmartInput.ICandidateAction} */
	var ArticleRefs = function ( visualizer, key )
	{
		this.visualizer = visualizer;
		this.key = key;
		this.__cands = {};
	};

	ArticleRefs.prototype.GetCandidates = function( handler )
	{
		var _self = this;
		getData( Conf.paths.list_articles, function( e ) {
			e = JSON.parse( e );

			for( var i in e.entries )
			{
				var ent = e.entries[i];
				_self.__cands[ ent.title ] = { "desc": ent.content, id: ent.id };
			}

			handler( _self.__cands );
		} );
	};

	ArticleRefs.prototype.Process = function( key )
	{
		var cand = this.__cands[ key ];
		if( !cand ) return false;

		this.visualizer.insertSnippet( "articlelink", { value: cand.id } );
		return true;
	};

	ArticleRefs.prototype.Retreat = function( sender, e )
	{
		return sender.value == "" && e.keyCode == 8; // Backspace
	};

	ns[ NS_EXPORT ]( EX_CLASS, "ArticleReference", ArticleRefs );
})();