Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Romain Courteaud
slapos.core
Commits
b0d3766e
Commit
b0d3766e
authored
Jun 01, 2012
by
Thomas Lechauve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge jquery.urlJS with vifib application
parent
cd8770e2
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
324 additions
and
339 deletions
+324
-339
jquery.urlJS/src/jquery.urljs.js
jquery.urlJS/src/jquery.urljs.js
+102
-105
vifib/index.html
vifib/index.html
+194
-194
vifib/static/js/core.js
vifib/static/js/core.js
+26
-40
vifib/static/js/urlHandler.js
vifib/static/js/urlHandler.js
+2
-0
No files found.
jquery.urlJS/src/jquery.urljs.js
View file @
b0d3766e
(
function
(
$
)
{
'
use strict
'
;
$
.
extend
({
router
:
{
routes
:
{
list
:
[],
current
:
null
,
$
.
extend
({
router
:
{
routes
:
{
list
:
[],
current
:
null
,
add
:
function
(
route
,
level
,
callback
,
context
)
{
var
r
,
keys
,
i
;
if
(
typeof
this
.
list
[
level
]
===
'
undefined
'
)
{
this
.
list
[
level
]
=
[];
}
r
=
{
'
route
'
:
route
,
'
level
'
:
level
,
'
callback
'
:
function
(
params
)
{
if
(
callback
!==
undefined
)
{
if
(
context
!==
undefined
)
{
callback
(
params
);
}
else
{
callback
.
call
(
context
,
params
);
}
add
:
function
(
route
,
level
,
callback
,
context
)
{
var
r
,
keys
,
i
;
if
(
typeof
this
.
list
[
level
]
===
'
undefined
'
)
{
this
.
list
[
level
]
=
[];
}
r
=
{
'
route
'
:
route
,
'
level
'
:
level
,
'
callback
'
:
function
(
params
)
{
if
(
callback
!==
undefined
)
{
if
(
context
===
undefined
)
{
callback
(
params
);
}
else
{
callback
.
call
(
context
,
params
);
}
}
,
}
},
i
=
this
.
list
[
level
].
length
;
this
.
list
[
level
][
i
]
=
r
;
},
i
=
this
.
list
[
level
].
length
;
this
.
list
[
level
][
i
]
=
r
;
},
clean
:
function
(
level
)
{
this
.
list
=
this
.
list
.
slice
(
0
,
level
);
},
clean
:
function
(
level
)
{
this
.
list
=
this
.
list
.
slice
(
0
,
level
);
},
cleanAll
:
function
()
{
this
.
list
=
this
.
list
.
slice
(
0
,
0
);
},
cleanAll
:
function
()
{
this
.
list
=
this
.
list
.
slice
(
0
,
0
);
},
search
:
function
(
hash
)
{
var
stop
=
false
,
i
=
0
,
j
=
0
,
regex
,
result
,
extracted
;
while
((
stop
===
false
)
&&
(
i
<
this
.
list
.
length
))
{
j
=
0
;
while
((
stop
===
false
)
&&
(
j
<
this
.
list
[
i
].
length
))
{
extracted
=
$
.
router
.
extractKeys
(
this
.
list
[
i
][
j
].
route
);
regex
=
new
RegExp
(
'
^
'
+
extracted
.
regex
+
'
$
'
);
if
(
regex
.
test
(
hash
.
route
))
{
result
=
regex
.
exec
(
hash
.
route
);
stop
=
true
;
result
.
shift
();
for
(
var
k
=
0
;
k
<
result
.
length
;
k
+=
1
)
{
hash
[
extracted
.
keys
[
k
]]
=
result
[
k
];
}
this
.
current
=
this
.
list
[
i
][
j
];
this
.
list
[
i
][
j
].
callback
(
hash
);
search
:
function
(
hash
)
{
var
stop
=
false
,
i
=
0
,
j
=
0
,
regex
,
result
,
extracted
;
while
((
stop
===
false
)
&&
(
i
<
this
.
list
.
length
))
{
j
=
0
;
while
((
stop
===
false
)
&&
(
j
<
this
.
list
[
i
].
length
))
{
extracted
=
$
.
router
.
extractKeys
(
this
.
list
[
i
][
j
].
route
);
regex
=
new
RegExp
(
'
^
'
+
extracted
.
regex
+
'
$
'
);
if
(
regex
.
test
(
hash
.
route
))
{
result
=
regex
.
exec
(
hash
.
route
);
stop
=
true
;
result
.
shift
();
for
(
var
k
=
0
;
k
<
result
.
length
;
k
+=
1
)
{
hash
[
extracted
.
keys
[
k
]]
=
result
[
k
];
}
j
+=
1
;
this
.
current
=
this
.
list
[
i
][
j
];
this
.
list
[
i
][
j
].
callback
(
hash
);
}
i
+=
1
;
j
+=
1
;
}
i
+=
1
;
}
},
}
},
extractKeys
:
function
(
regex
)
{
var
re_key
=
new
RegExp
(
/:
(\w
+
)
/
),
keys
=
[],
result
;
while
(
re_key
.
test
(
regex
))
{
result
=
re_key
.
exec
(
regex
);
keys
.
push
(
result
[
1
]);
regex
=
regex
.
replace
(
result
[
0
],
'
([^
\
/]+)
'
);
}
return
{
'
regex
'
:
regex
,
'
keys
'
:
keys
}
},
extractKeys
:
function
(
regex
)
{
var
re_key
=
new
RegExp
(
/:
(\w
+
)
/
),
keys
=
[],
result
;
while
(
re_key
.
test
(
regex
))
{
result
=
re_key
.
exec
(
regex
);
keys
.
push
(
result
[
1
]);
regex
=
regex
.
replace
(
result
[
0
],
'
([^
\
/]+)
'
);
}
return
{
'
regex
'
:
regex
,
'
keys
'
:
keys
}
},
deserialize
:
function
(
params
)
{
var
result
=
{},
p
,
params
=
params
.
split
(
'
&
'
);
while
(
params
.
length
)
{
p
=
params
.
shift
().
split
(
'
=
'
);
if
(
p
[
0
]
!==
''
)
{
if
(
p
.
length
===
2
)
{
result
[
p
[
0
]]
=
p
[
1
]
===
'
true
'
?
true
:
p
[
1
];
}
else
{
result
[
p
[
0
]]
=
true
;
}
deserialize
:
function
(
params
)
{
var
result
=
{},
p
,
params
=
params
.
split
(
'
&
'
);
while
(
params
.
length
)
{
p
=
params
.
shift
().
split
(
'
=
'
);
if
(
p
[
0
]
!==
''
)
{
if
(
p
.
length
===
2
)
{
result
[
p
[
0
]]
=
p
[
1
]
===
'
true
'
?
true
:
p
[
1
];
}
else
{
result
[
p
[
0
]]
=
true
;
}
}
return
result
;
},
}
return
result
;
},
serialize
:
function
(
obj
)
{
return
$
.
param
(
obj
);
},
serialize
:
function
(
obj
)
{
return
$
.
param
(
obj
);
},
parseHash
:
function
(
hashTag
)
{
var
re
=
new
RegExp
(
/
(?:
^#
([
a-zA-Z0-9
\/
_-
]
+
))(?:\?([
A-Za-z0-9
\/
&=_-
]
+
))?
/g
),
groups
=
re
.
exec
(
hashTag
),
r
,
params
=
{};
groups
.
shift
();
// route
r
=
groups
[
0
];
// params
if
(
groups
[
1
]
!==
undefined
)
{
params
=
this
.
deserialize
(
groups
[
1
]);
}
return
params
.
length
===
0
?
{
'
route
'
:
r
}
:
$
.
extend
({
'
route
'
:
r
},
params
);
},
parseHash
:
function
(
hashTag
)
{
var
re
=
new
RegExp
(
/
(?:
^#
?
([
a-zA-Z0-9
\/
_-
]
+
))(?:\?([
A-Za-z0-9
\/
&=_-
]
+
))?
/g
),
groups
=
re
.
exec
(
hashTag
),
r
,
params
=
{};
groups
.
shift
();
// route
r
=
groups
[
0
];
// params
if
(
groups
[
1
]
!==
undefined
)
{
params
=
this
.
deserialize
(
groups
[
1
]);
}
return
params
.
length
===
0
?
{
'
route
'
:
r
}
:
$
.
extend
({
'
route
'
:
r
},
params
);
},
hashHandler
:
function
()
{
var
hashTag
=
window
.
location
.
href
.
split
(
'
#
'
)[
1
],
hashInfo
=
this
.
parseHash
(
hashTag
);
this
.
routes
.
call
(
hashInfo
)
},
}
});
hashHandler
:
function
()
{
var
hashTag
=
window
.
location
.
href
.
split
(
'
#
'
)[
1
],
hashInfo
=
$
.
router
.
parseHash
(
hashTag
);
$
.
router
.
routes
.
search
(
hashInfo
)
},
}
});
$
(
window
).
bind
(
'
hashchange
'
,
$
.
router
.
hashchangeHandler
);
$
(
window
).
bind
(
'
load
'
,
$
.
router
.
hashchangeHandler
);
}(
jQuery
));
$
(
window
).
bind
(
'
hashchange
'
,
$
.
router
.
hashHandler
);
$
(
window
).
bind
(
'
load
'
,
$
.
router
.
hashHandler
);
vifib/index.html
View file @
b0d3766e
This diff is collapsed.
Click to expand it.
vifib/static/js/core.js
View file @
b0d3766e
...
...
@@ -5,31 +5,7 @@
*/
(
function
(
$
)
{
'
use strict
'
;
var
routes
=
{
'
/catalog
'
:
'
showCatalog
'
,
'
/catalog/all
'
:
'
showCatalogAll
'
,
'
/instance
'
:
'
requestInstance
'
,
'
/instance/:url
'
:
'
showInstance
'
,
'
/instance/:url/bang
'
:
'
showBangInstance
'
,
'
/computers
'
:
'
listComputers
'
,
'
/instances
'
:
'
listInstances
'
,
'
/invoices
'
:
'
listInvoices
'
,
'
/dashboard
'
:
'
showDashboard
'
},
router
=
function
(
e
,
d
)
{
var
$this
=
$
(
this
);
$
.
each
(
routes
,
function
(
pattern
,
callback
)
{
pattern
=
pattern
.
replace
(
/:
\w
+/g
,
'
([^
\
/]+)
'
);
var
regex
=
new
RegExp
(
'
^
'
+
pattern
+
'
$
'
),
result
=
regex
.
exec
(
d
);
if
(
result
)
{
result
.
shift
();
methods
[
callback
].
apply
(
$this
,
result
);
}
});
},
getDate
=
function
()
{
var
getDate
=
function
()
{
var
today
=
new
Date
();
return
[
today
.
getFullYear
(),
today
.
getMonth
(),
today
.
getDay
()].
join
(
'
/
'
)
+
'
'
+
[
today
.
getHours
(),
today
.
getMinutes
(),
today
.
getSeconds
()].
join
(
'
:
'
);
...
...
@@ -83,23 +59,33 @@
methods
=
{
init
:
function
()
{
// Initialize slapos in this context
$
(
this
).
slapos
({
'
host
'
:
'
http://10.8.2.34:12006/erp5/portal_vifib_rest_api_v1
'
});
var
$this
=
$
(
this
);
// Bind Loading content
$
(
'
#loading
'
).
ajaxStart
(
function
()
{
$
(
this
).
spin
(
spinOptions
);
}).
ajaxStop
(
function
()
{
$
(
this
).
spin
(
false
);
});
// Bind to urlChange event
var
routes
=
[];
routes
[
0
]
=
[
[
'
/catalog
'
,
methods
[
'
showCatalog
'
]],
[
'
/catalog/all
'
,
methods
[
'
showCatalogAll
'
]],
[
'
/instance
'
,
methods
[
'
requestInstance
'
]],
[
'
/instance/:url
'
,
methods
[
'
showInstance
'
]],
[
'
/instance/:url/bang
'
,
methods
[
'
showBangInstance
'
]],
[
'
/computers
'
,
methods
[
'
listComputers
'
]],
[
'
/instances
'
,
methods
[
'
listInstances
'
]],
[
'
/invoices
'
,
methods
[
'
listInvoices
'
]],
[
'
/dashboard
'
,
methods
[
'
showDashboard
'
]]
];
return
this
.
each
(
function
()
{
$
.
subscribe
(
'
urlChange
'
,
function
(
e
,
d
)
{
router
.
call
(
$this
,
e
,
d
);
});
$
.
subscribe
(
'
auth
'
,
function
(
e
,
d
)
{
$
(
this
).
vifib
(
'
authenticate
'
,
d
);
// Initialize slapos in this context
$
(
this
).
slapos
({
'
host
'
:
'
http://10.8.2.34:12006/erp5/portal_vifib_rest_api_v1
'
});
// Bind Loading content
$
(
'
#loading
'
).
ajaxStart
(
function
()
{
$
(
this
).
spin
(
spinOptions
);
}).
ajaxStop
(
function
()
{
$
(
this
).
spin
(
false
);
});
for
(
var
level
=
0
;
level
<
routes
.
length
;
level
+=
1
)
{
for
(
var
i
=
0
;
i
<
routes
[
level
].
length
;
i
+=
1
)
{
var
r
=
routes
[
level
][
i
];
$
.
router
.
routes
.
add
(
r
[
0
],
level
,
r
[
1
],
$
(
this
));
}
}
});
},
...
...
vifib/static/js/urlHandler.js
View file @
b0d3766e
...
...
@@ -61,5 +61,7 @@ $.redirectHandler = function(e, url){ window.location.hash = $.genHash(url); };
$
.
redirect
=
function
(
url
){
$
.
publish
(
'
redirect
'
,
[
url
]);
};
$
.
subscribe
(
'
redirect
'
,
$
.
redirectHandler
)
console
.
log
(
"
plop
"
)
$
(
window
).
bind
(
'
hashchange
'
,
$
.
hashHandler
);
$
(
window
).
bind
(
'
load
'
,
$
.
hashHandler
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment