Source: MoviesList.js

require ('./iView.js');
/**
* @param {Telll} t the telll object
* @author Monsenhor filipo at kobkob.org
* @constructor
*/
function MoviesList(t){
    this.t = t;
    this._init(t);
}
MoviesList.prototype =Object.create(iView.prototype);

/**
* @param t {} 
* @return bool
*/
MoviesList.prototype._init = function(t){
    this.state = null;
    this._showWidget(t.store);
    return null;
}

/**
* @param data {} 
* @return bool
*/
MoviesList.prototype._showWidget = function(data){
    data.movies.forEach(function (m){
        m.dispTitle = m.title.replace(/ *\{[^}]*\} */g, "");;
        m.title = escape(m.title);
    });
    var tmpl = require('./templates/movies_list.mtjs');
    var html = Mustache.render(tmpl.html, data);
    if (tmpl.css)
    $('<style id="movies-list-css">'+tmpl.css+'</style>').appendTo('head');
    $(html).appendTo('body');
    var telll = this.t;
    var me = this;

    // The popup 
    $('<div id="popup-movies-list" class="popup"></div>').appendTo('body');
    $(".telll-movies-list-widget").appendTo('#popup-movies-list').fadeIn();
    $('html').addClass('overlay');

    /* // other buttons
    $( ".tag-titlebar button.trackms" ).on("click", function(e) {
        e.preventDefault();
        // The draggable pointer
        me.drgPointer();
	me.state = "tracking";
	
    });
    $( ".tag-titlebar button.tag" ).on("click", function(e) {
        e.preventDefault();
        // The tag editor
        me.tagEditor();
	me.state = "tagging";
	
    });
    */
    $( ".movies-list-titlebar button.close" ).on("click", function(e) {
        e.preventDefault();
	// do stuff
	me.state = "detached";
	me.detach();
    });
    $( ".movie-thumb" ).on("click", function(e) {
        e.preventDefault();
	    //selectedMovie(e, this);
	    console.log("Its suposed i never will be clicked!!!! hmmmm ....");
    });
    
    // Movie labels
    $(".telll-movie-element").on("mouseenter", function (e) {
        $(this).find('.movie-label').css('cursor','pointer');
        $(this).find('.movie-label').fadeIn("slow");
    });
    $('.movie-label').on('click',function(e){
        e.preventDefault();
	var theThumb = $(this).parent().find("img");
        var movieData = JSON.parse(theThumb.attr('data'));
        me.state = 'selected';
        me.emit(me.state, movieData);
        telll.setCookie('movieId',movieData.id,telll.conf.extime);
    });
    $(".telll-movie-element").on("mouseleave", function () {
        var element = this;
        $(this).find('.movie-label').fadeOut("fast");
    });

    return true;
};

/**
* @return null
*/
MoviesList.prototype.detach = function(){
    $('.telll-movies-list-widget').detach();
    $('div#popup-movies-list').detach();
};

module.exports = {MoviesList:MoviesList};