Linux-DVB-DVBT-Apps-QuartzPVR

 view release on metacpan or  search on metacpan

js/tvguide/Pages/SearchList.js  view on Meta::CPAN

/*
Manages a list of results from a program search

*/

/*======================================================================================================*/
//Constructor
/*======================================================================================================*/

SearchList.settings = {} ;

// The last search object used in a search
SearchList.latestSearch = {} ;

//Create the popup object we'll use
SearchList.popup = new Popup();

// A dummy Prog to use with setting up new recordings
SearchList.srchProg = new Prog() ;

//Map search settings response
SearchList.SEARCH_MAP = {
	0	: "title", 
	1	: "desc",
	2	: "genre",
	3	: "channel",
	4	: "listingsType",
} ;

//Map from array index to entry field
SearchList.MAP = {
	0	: "date", 
	
	1	: "progs_array"
} ;

SearchList.SELECT = {} ;
SearchList.SELECT.ANY_CHAN = "-Any Channel-" ;
SearchList.SELECT.ANY_TYPE = "-Any-" ;


/*------------------------------------------------------------------------------------------------------*/
//Each entry is a date
SearchList.sort = function(a,b) {
	var cmp = DateUtils.dateCompare(a.date, b.date);
	return cmp;
} 

// Sort programs by date
SearchList.subsort = function(a,b) {
	// NOTE: Invert compare to sort "descending"
	var cmp = Prog.prog_sort(a, b) ;
	return cmp;
} 

/*------------------------------------------------------------------------------------------------------*/
//Change record level on an existing recording (found during search)
//SearchList.setRecordings = function(record, pid, rid, priority)
SearchList.setRecordings = function(prog)
{
	SearchList.settings.app.setSearchRec(prog, SearchList.latestSearch) ;
}



/*------------------------------------------------------------------------------------------------------*/
SearchList.args = {
		index 		: "date" ,
		subindex 	: "progsList" ,
		sort 		: SearchList.sort,
		rowClass 	: "",
		subrowClass : "lprog",
			
		popupClassName 	: "recListPop",
		
		// used to change an existing Prog (found in search)
		recselCallback 	: SearchList.setRecordings,
		priCallback 	: SearchList.setRecordings
			
	} ;


/*------------------------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------------------------*/
function SearchList()
{
	RecList.call(this, SearchList.args) ;
	
	// add a ref to the global settings
	this.settings = SearchList.settings ;

	for (var i in SearchList.SEARCH_MAP)
	{
		var field = SearchList.SEARCH_MAP[i] ;
		this[field] = "" ;
	}

	// filled with (dynamic) list of channels
	this.channels = [] ;

	// DOM nodes
	this.searchBar = null ;
	this.typeSelector = null ;
	this.chanSelector = null ;
	this.recList = null ;
	
	// Init the search Prog
	SearchList.srchProg.record = 0 ;
	SearchList.srchProg.priority = Prog.DEFAULT_PRIORITY ;
	this.updateProg() ;
}

SearchList.initSearch = function(searchObj)
{
	if (!searchObj || (typeof searchObj != "object"))
	{
		searchObj = {} ;
	}
	for (var i in SearchList.SEARCH_MAP)
	{
		var field = SearchList.SEARCH_MAP[i] ;
		if (!searchObj.hasOwnProperty(field))
		{
			searchObj[field] = "" ;
		}
	}

	return searchObj ;
}

SearchList.copySearch = function(searchObj, destObj)
{
	for (var i in SearchList.SEARCH_MAP)
	{

js/tvguide/Pages/SearchList.js  view on Meta::CPAN

			
			// Ensure the recording select "dialog" shows the correct options
			searchObject.update_rec_sel() ;

			// save for re-use when changing recordings
			SearchList.copySearch(searchObject, SearchList.latestSearch) ;
		} ;
	}
	
	// create selector
	this.chanSelector = this.display_labelled_select(ol, 
			SearchList.settings.LABEL_CHAN_PX, 'Channel:', 
			SearchList.settings.EDIT_CHAN_PX, this.channel, this.channels, channelNames, 
			'select',
			createChangeHandler(this)) ;
}

/*------------------------------------------------------------------------------------------------------*/
// Display the listings type selector
SearchList.prototype.display_type_select = function(ol)
{
	// Get list of channels
	var types = [] ;
	var anyTypes = SearchList.SELECT.ANY_TYPE ;
	
	types.push(anyTypes) ;
	types.push("TV") ;
	types.push("HD-TV") ;
	types.push("Radio") ;
		
	function createChangeHandler(searchObject) {
		return function() {
			
			//var options = this.options ;
			//var option = options[this.selectedIndex] ;
			//var value = searchObject.typeValue(option.value) ;
			//
			// this.options doesn't seem to work on PS3?
			var value = searchObject.typeValue(types[this.selectedIndex]) ;

			//log.debug("type change handler : value "+value+" idx="+ this.selectedIndex+" val="+option.value);			
			
			// Update the channel list
			searchObject.update_chan_select() ;
			
			// save for re-use when changing recordings
			SearchList.copySearch(searchObject, SearchList.latestSearch) ;
		} ;
	}
	
	// create selector
	this.typeSelector = this.display_labelled_select(ol, 
			SearchList.settings.LABEL_TYPE_PX, 'Type:', 
			SearchList.settings.EDIT_TYPE_PX, this.listingsType, types, types,
			'select',
			createChangeHandler(this)) ;
}


/*------------------------------------------------------------------------------------------------------*/
SearchList.prototype.popup_fuzzyrecsel_contents = function(popupDiv, record_select)
{
	popupDiv.className = this.popupClassName ;

	var recUl = document.createElement("ul");
	recUl.className = "recprog" ;

	Prog.create_recSelList(recUl, "FUZZY", SearchList.srchProg, record_select) ;
	
	popupDiv.appendChild(recUl) ;
	
	this.recList = recUl ;
	
	// Find all entries that rely on the channel name being specified
	this.recList.reqChannel = $(".chan", $(this.recList)).toArray() ;

	// Update the dialog based on the channel name selection 
	this.update_rec_sel() ;
	
}

/*------------------------------------------------------------------------------------------------------*/
//Add a popup window for recording selection on multiple lines of the TvList display. 
//
SearchList.prototype.add_fuzzy_record_popup = function(node)
{
	var thisObj = this ;
	
	// use this width
	var popup_width = thisObj.settings.POPUP_WIDTH_PX ;
	
	var progSettings = {
		//-----------------------------------------------------
		create_popup: function(settings, x, y, callback) {
			
			var popupDiv = document.createElement("div");
			thisObj.popup_fuzzyrecsel_contents(popupDiv, callback) ; 
			var popupObj = {
				dom 	: popupDiv
			} ;
			
			return popupObj ;
		},
		//-----------------------------------------------------
		popup_node	: function(settings, popupObj) {
			return popupObj.dom ;
		},
		//-----------------------------------------------------
		show_popup	: function(settings, popupObj, x, y) {
			
			var popupDiv = popupObj.dom ;
			
			// ensure we're over the popupDiv to stop the popup cycling up/down
			x = x - 10 ;
			y = y - 10 ;
			
			// Show the popup window
			thisObj.popup.show(popupDiv, x, y, popup_width);
			thisObj.popup.adjustXY(x, y) ;
		},
		//-----------------------------------------------------
		hide_popup	: function(settings, popupObj) {
			thisObj.popup.hide();
		},
		//-----------------------------------------------------
		callback	: function(settings, vars) {
			
			var progObject = vars.prog ;
			var new_rec = vars.val ;
			
			// only update if changed
			if (new_rec != progObject.record)
			{
				// Call the fuzzy record method
				var old_rec = progObject.record ;
				progObject.record = new_rec ;
				SearchList.setFuzzyRecordings(progObject);
				
			}

		}
	} ;
	
	PopupHandler.add_popup(node, progSettings) ;
}

/*------------------------------------------------------------------------------------------------------*/
//Add a record level selection element
SearchList.prototype.display_fuzzyrecsel = function(ol)
{
	// Container
	var li = this._display_li(ol, this.settings.REC_PX, "") ;
	
		var a = document.createElement("a");
		a.id = "fuzzyrecsel" ;
		li.appendChild(a) ;

		this.fuzzyrecsel = a ;
		
			var img = document.createElement("img");
			img.src = Prog.RecImg(0) ; 
			a.appendChild(img) ;

			// add a popup display to show program details
			this.add_fuzzy_record_popup(a) ;
			
	return li ;
}

/*------------------------------------------------------------------------------------------------------*/
//Add a record level selection element
SearchList.prototype.display_searchButton = function(ol)
{
	// Container
	var li = this._display_li(ol, this.settings.SEARCH_PX, "") ;
	
		var a = document.createElement("a");
		a.id = "searchButton" ;
		a.setAttribute("title", "Click to search for specified program(s)") ;
		li.appendChild(a) ;
		
		this.searchButton = a ;
	
			var img = document.createElement("img");
			
			// TODO: sort out image cache etc
			img.src = this.settings.app.getImage("search") ;
			a.appendChild(img) ;
			
	var app = SearchList.settings.app ;
	$(a).click(app.create_handler(app.showSearch, SearchList.latestSearch)) ; 

	return li ;
}



/*------------------------------------------------------------------------------------------------------*/
// Update the search params - passed in via JSON
//
SearchList.prototype.update_search = function(search_data)
{
	Profile.start('SearchList.update') ;

	// Create a mapping from name -> value
	var entry_args = [] ;
	for (var i in SearchList.SEARCH_MAP)
	{
		var field = SearchList.SEARCH_MAP[i] ;
		if (search_data[i])
		{
			this[field] = search_data[i] ;
		}
	}

	Profile.stop('SearchList.update') ;
}


/*------------------------------------------------------------------------------------------------------*/
//Create a text editor
//
SearchList.prototype.factory_edit_search = function(type)
{
var searchList = this ;



( run in 1.166 second using v1.01-cache-2.11-cpan-364913b4093 )