$.Controller("MYAPP.Router",
/* @Static */
{},
/* @Prototype */
{
"init": function(){
$.route.ready(false);
// eg solutions or projects
$.route(":resource", { "resource": "" });
// eg solutions/100 or projects/200
$.route(":resource/:id", { "resource": "", "id": "" });
$.route(":resource/:id", { "resource": "", "id": "" });
// eg solutions/100/projects or projects/200/libraries
$.route(":resource/:id/:sidebar_item", { "resource": "", "id": "", "sidebar_item": "" });
$.route(":resource/:id/:sidebar_item", { "resource": "", "id": "", "sidebar_item": "" });
// eg solutions/100/projects/add or projects/200/libraries/add
$.route(":resource/:id/:sidebar_item/:action", { "resource": "", "id": "", "sidebar_item": "" , "action": "" });
},
$.route(":resource/:id/:sidebar_item/:action", { "resource": "", "id": "", "sidebar_item": "" , "action": "" });
},
"{$.route} resource add":function(route, event, newValue, oldValue){
// this is getting called for all above examples which is expected behavior,
// but I dont want to use this as I need to write if() conditions to render the corresponding page
},
"{$.route} resource=solutions add": function(route, event, newValue, oldValue){
// this is NOT getting called when location.hash is solutions
},
"{$.route} resource=solutions set": function(route, event, newValue, oldValue){
// this is NOT getting called when location.hash is solutions
},
"{$.route} resource=solutions, id remove": function(route, event, newValue, oldValue){
// this is NOT getting called when location.hash is changed from solutions/1 to solutions
},
"{$.route} resource=solutions, id add": function(route, event, newValue, oldValue){
// this is NOT getting called when location.hash is
// - changed from solutions to solutions/2// this is getting called for all above examples which is expected behavior,
// but I dont want to use this as I need to write if() conditions to render the corresponding page
},
"{$.route} resource=solutions add": function(route, event, newValue, oldValue){
// this is NOT getting called when location.hash is solutions
},
"{$.route} resource=solutions set": function(route, event, newValue, oldValue){
// this is NOT getting called when location.hash is solutions
},
"{$.route} resource=solutions, id remove": function(route, event, newValue, oldValue){
// this is NOT getting called when location.hash is changed from solutions/1 to solutions
},
"{$.route} resource=solutions, id add": function(route, event, newValue, oldValue){
// this is NOT getting called when location.hash is
// - changed from solutions to solutions/2/projects
// - changed from solutions to solutions/2/projects/add
// - changed from solutions/1 to solutions/2
},
"{$.route} resource=solutions, id set": function(route, event, newValue, oldValue){
// this is NOT getting called when location.hash is
// - changed from solutions to solutions/2
// - changed from solutions to solutions/2/projects
// - changed from solutions to solutions/2/projects/add
// - changed from solutions/1 to solutions/2
},
"{$.route} resource=solutions, id set": function(route, event, newValue, oldValue){
// this is NOT getting called when location.hash is
// - changed from solutions to solutions/2
// - changed from solutions to solutions/2/projects
// - changed from solutions to solutions/2/projects/add
// - changed from solutions/1 to solutions/2
},
"{$.route} resource=solutions, id=* sidebar_item set": function(route, event, newValue, oldValue){
// is this SUPPORTED - sidebar_item is set with resource=solutions and id=(some value 1 or 2 or 3)
// I can get id using $.data.attr("id");
},
"{$.route} resource=solutions, id=* sidebar_item=* action set": function(route, event, newValue, oldValue){
// is this SUPPORTED - action is set with resource=solutions, id=(some value 1 or 2 or 3), sidebar_item=(some value)
// is this SUPPORTED - sidebar_item is set with resource=solutions and id=(some value 1 or 2 or 3)
// I can get id using $.data.attr("id");
},
"{$.route} resource=solutions, id=* sidebar_item=* action set": function(route, event, newValue, oldValue){
// is this SUPPORTED - action is set with resource=solutions, id=(some value 1 or 2 or 3), sidebar_item=(some value)
// I can get id using $.data.attr("id") and sidebar_item using $.data.attr("sidebar_item");
}
});
// attached to body
$("body").myapp_router();
$.route.ready(true); is invoked in controller MYAPP.Login "success" method.
1


