| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | /********************************************************************** | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | **********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | define(function(require){ var module = {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //var DEBUG = DEBUG != null ? DEBUG : true
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var util = require('lib/util') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var actions = require('lib/actions') | 
					
						
							|  |  |  | var features = require('lib/features') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var core = require('features/core') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-28 07:23:28 +03:00
										 |  |  | // XXX add .hash support for in-location .current setting when no index
 | 
					
						
							|  |  |  | // 		available... 
 | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | // XXX should this or LocationLocalStorage save/load location (now it's 
 | 
					
						
							|  |  |  | // 		done by history)
 | 
					
						
							|  |  |  | // XXX this should provide mechaincs to define location handlers, i.e.
 | 
					
						
							|  |  |  | // 		a set for loader/saver per location type (.method)
 | 
					
						
							|  |  |  | // XXX revise the wording...
 | 
					
						
							|  |  |  | // 		.method?
 | 
					
						
							|  |  |  | // 		.path or .url
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var LocationActions = actions.Actions({ | 
					
						
							|  |  |  | 	// Format:
 | 
					
						
							|  |  |  | 	// 	{
 | 
					
						
							|  |  |  | 	// 		path: <base-path>,
 | 
					
						
							|  |  |  | 	// 		method: <load-method>,
 | 
					
						
							| 
									
										
										
										
											2015-12-28 07:23:28 +03:00
										 |  |  | 	// 		current: <current-gid>,
 | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 	// 	}
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// NOTE: these will remove the trailing '/' (or '\') from .path 
 | 
					
						
							|  |  |  | 	// 		unless the path is root (i.e. "/")...
 | 
					
						
							|  |  |  | 	// 		...this is mainly to facilitate better browse support, i.e.
 | 
					
						
							|  |  |  | 	// 		to open the dir (open parent + select current) and not 
 | 
					
						
							|  |  |  | 	// 		within the dir
 | 
					
						
							|  |  |  | 	__location: null, | 
					
						
							|  |  |  | 	get location(){ | 
					
						
							|  |  |  | 		this.__location = this.__location || {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		var b = this.__location.path | 
					
						
							|  |  |  | 		if(b && b != '/' && b != '\\'){ | 
					
						
							|  |  |  | 			b = util.normalizePath(b) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if(b){ | 
					
						
							|  |  |  | 			this.__location.path = b | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-12-29 01:02:57 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-31 05:44:14 +03:00
										 |  |  | 		this.__location.current = this.current | 
					
						
							| 
									
										
										
										
											2015-12-29 01:02:57 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 		return this.__location | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	set location(value){ | 
					
						
							|  |  |  | 		// got a path...
 | 
					
						
							|  |  |  | 		if(typeof(value) == typeof('str')){ | 
					
						
							|  |  |  | 			var path = value | 
					
						
							|  |  |  | 			// XXX get a better reasonable default...
 | 
					
						
							|  |  |  | 			var method = this.__location  | 
					
						
							|  |  |  | 				&& this.__location.method  | 
					
						
							|  |  |  | 					|| undefined  | 
					
						
							| 
									
										
										
										
											2015-12-28 07:23:28 +03:00
										 |  |  | 			var cur = this.current | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// got an object...
 | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			var path = value.path | 
					
						
							|  |  |  | 			var method = value.method | 
					
						
							| 
									
										
										
										
											2015-12-28 07:23:28 +03:00
										 |  |  | 			var cur = value.current | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// normalize path if it's not root...
 | 
					
						
							|  |  |  | 		if(path != '/' && path != '\\'){ | 
					
						
							|  |  |  | 			path = util.normalizePath(path) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		this.__location = { | 
					
						
							|  |  |  | 			path: path, | 
					
						
							|  |  |  | 			method: method, | 
					
						
							| 
									
										
										
										
											2015-12-28 07:23:28 +03:00
										 |  |  | 			current: cur, | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-29 01:02:57 +03:00
										 |  |  | 		var res = this[value.method || 'loadIndex'](path) | 
					
						
							| 
									
										
										
										
											2015-12-28 07:23:28 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// XXX load current...
 | 
					
						
							| 
									
										
										
										
											2015-12-29 01:02:57 +03:00
										 |  |  | 		if(res.then != null){ | 
					
						
							|  |  |  | 			res.then(function(){ | 
					
						
							|  |  |  | 				this.current = cur | 
					
						
							|  |  |  | 			}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			this.current = cur | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 	}, | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.Location = core.ImageGridFeatures.Feature({ | 
					
						
							|  |  |  | 	title: '', | 
					
						
							|  |  |  | 	doc: '', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tag: 'location', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	actions: LocationActions, | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /********************************************************************** | 
					
						
							|  |  |  | * vim:set ts=4 sw=4 :                                                */ | 
					
						
							|  |  |  | return module }) |