Changeset - 07f4193083fd
[Not reviewed]
beta
0 1 0
Marcin Kuzminski - 13 years ago 2013-02-25 23:16:36
marcin@python-works.com
extra params in pyroutes now generate GET params
1 file changed with 13 insertions and 0 deletions:
0 comments (0 inline, 0 general)
rhodecode/public/js/rhodecode.js
Show inline comments
 
@@ -257,102 +257,115 @@ var pyroutes = (function() {
 
                            while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') {
 
                                if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) {
 
                                    field_list.push(field_match[1]);
 
                                }
 
                                else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) {
 
                                    field_list.push(field_match[1]);
 
                                }
 
                                else {
 
                                    throw('[sprintf] huh?');
 
                                }
 
                            }
 
                        }
 
                        else {
 
                            throw('[sprintf] huh?');
 
                        }
 
                        match[2] = field_list;
 
                    }
 
                    else {
 
                        arg_names |= 2;
 
                    }
 
                    if (arg_names === 3) {
 
                        throw('[sprintf] mixing positional and named placeholders is not (yet) supported');
 
                    }
 
                    parse_tree.push(match);
 
                }
 
                else {
 
                    throw('[sprintf] huh?');
 
                }
 
                _fmt = _fmt.substring(match[0].length);
 
            }
 
            return parse_tree;
 
        };
 

	
 
        return str_format;
 
    })();
 

	
 
    var vsprintf = function(fmt, argv) {
 
        argv.unshift(fmt);
 
        return sprintf.apply(null, argv);
 
    };
 
    return {
 
        'url': function(route_name, params) {
 
            var result = route_name;
 
            if (typeof(params) != 'object'){
 
            	params = {};
 
            }
 
            if (matchlist.hasOwnProperty(route_name)) {
 
                var route = matchlist[route_name];
 
                // param substitution
 
                for(var i=0; i < route[1].length; i++) {
 

	
 
                   if (!params.hasOwnProperty(route[1][i]))
 
                        throw new Error(route[1][i] + ' missing in "' + route_name + '" route generation');
 
                }
 
                result = sprintf(route[0], params);
 
                
 
                var ret = [];
 
                //extra params => GET
 
                for(param in params){
 
                	if (route[1].indexOf(param) == -1){
 
                		ret.push(encodeURIComponent(param) + "=" + encodeURIComponent(params[param]));	
 
                	}
 
                }
 
                var _parts = ret.join("&");
 
                if(_parts){
 
                	result = result +'?'+ _parts
 
                }
 
            }
 

	
 
            return result;
 
        },
 
    	'register': function(route_name, route_tmpl, req_params) {
 
    		if (typeof(req_params) != 'object') {
 
    			req_params = [];
 
    		}
 
    		//fix escape
 
    		route_tmpl = unescape(route_tmpl);
 
    		keys = [];
 
    		for (o in req_params){
 
    			keys.push(req_params[o])
 
    		}
 
    		matchlist[route_name] = [
 
    		    route_tmpl,
 
    		    keys
 
    		]
 
    	},
 
    	'_routes': function(){
 
    		return matchlist;
 
    	}
 
    }
 
})();
 

	
 

	
 

	
 
/**
 
 * GLOBAL YUI Shortcuts
 
 */
 
var YUC = YAHOO.util.Connect;
 
var YUD = YAHOO.util.Dom;
 
var YUE = YAHOO.util.Event;
 
var YUQ = YAHOO.util.Selector.query;
 

	
 
// defines if push state is enabled for this browser ?
 
var push_state_enabled = Boolean(
 
		window.history && window.history.pushState && window.history.replaceState
 
		&& !(   /* disable for versions of iOS before version 4.3 (8F190) */
 
				(/ Mobile\/([1-7][a-z]|(8([abcde]|f(1[0-8]))))/i).test(navigator.userAgent)
 
				/* disable for the mercury iOS browser, or at least older versions of the webkit engine */
 
				|| (/AppleWebKit\/5([0-2]|3[0-2])/i).test(navigator.userAgent)
 
		)
 
);
 

	
 
var _run_callbacks = function(callbacks){
 
	if (callbacks !== undefined){
 
		var _l = callbacks.length;
0 comments (0 inline, 0 general)