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
0
Merge Requests
0
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
Roque
slapos.core
Commits
406112e2
Commit
406112e2
authored
May 24, 2012
by
Thomas Lechauve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix tests bugs (Firefox) and add storage tests
parent
5b10ab7f
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
64 additions
and
20 deletions
+64
-20
jquery.slapos/src/jquery.slapos.js
jquery.slapos/src/jquery.slapos.js
+8
-3
jquery.slapos/test/jquery.slapos_test.js
jquery.slapos/test/jquery.slapos_test.js
+37
-3
vifib/static/js/core.js
vifib/static/js/core.js
+11
-11
vifib/static/js/jquery.slapos.js
vifib/static/js/jquery.slapos.js
+8
-3
No files found.
jquery.slapos/src/jquery.slapos.js
View file @
406112e2
...
@@ -27,6 +27,10 @@
...
@@ -27,6 +27,10 @@
return
$
(
this
).
slapos
(
'
store
'
,
'
clientID
'
,
value
);
return
$
(
this
).
slapos
(
'
store
'
,
'
clientID
'
,
value
);
},
},
deleteStore
:
function
(
name
)
{
delete
window
.
localStorage
[
name
];
},
/* Local storage method */
/* Local storage method */
lStore
:
function
(
name
,
value
)
{
lStore
:
function
(
name
,
value
)
{
if
(
Modernizr
.
localstorage
)
{
if
(
Modernizr
.
localstorage
)
{
...
@@ -82,10 +86,10 @@
...
@@ -82,10 +86,10 @@
datatype
:
'
json
'
,
datatype
:
'
json
'
,
context
:
$
(
this
),
context
:
$
(
this
),
beforeSend
:
function
(
xhr
)
{
beforeSend
:
function
(
xhr
)
{
//
xhr.setRequestHeader('REMOTE_USER', 'test_vifib_customer');
xhr
.
setRequestHeader
(
'
REMOTE_USER
'
,
'
test_vifib_customer
'
);
xhr
.
setRequestHeader
(
'
Accept
'
,
'
application/json
'
);
xhr
.
setRequestHeader
(
'
Accept
'
,
'
application/json
'
);
if
(
$
(
this
).
slapos
(
'
access_token
'
)
&&
authentication
)
{
if
(
$
(
this
).
slapos
(
'
access_token
'
)
&&
authentication
)
{
xhr
.
setRequestHeader
(
'
Authorization
'
,
$
(
this
).
slapos
(
'
store
'
,
'
token_type
'
)
+
'
'
+
$
(
this
).
slapos
(
'
access_token
'
));
//
xhr.setRequestHeader('Authorization', $(this).slapos('store', 'token_type') + ' ' + $(this).slapos('access_token'));
}
}
}
}
};
};
...
@@ -116,7 +120,8 @@
...
@@ -116,7 +120,8 @@
discovery
:
function
(
callback
)
{
discovery
:
function
(
callback
)
{
return
this
.
each
(
function
()
{
return
this
.
each
(
function
()
{
$
.
ajax
({
$
.
ajax
({
url
:
'
http://10.8.2.34:12006/erp5/portal_vifib_rest_api_v1
'
,
url
:
$
(
this
).
slapos
(
"
host
"
),
context
:
$
(
this
),
dataType
:
'
json
'
,
dataType
:
'
json
'
,
beforeSend
:
function
(
xhr
)
{
beforeSend
:
function
(
xhr
)
{
xhr
.
setRequestHeader
(
'
Accept
'
,
'
application/json
'
);
xhr
.
setRequestHeader
(
'
Accept
'
,
'
application/json
'
);
...
...
jquery.slapos/test/jquery.slapos_test.js
View file @
406112e2
...
@@ -2,7 +2,6 @@ jQuery(function(){
...
@@ -2,7 +2,6 @@ jQuery(function(){
var
response
,
responseBody
,
url
,
data
;
var
response
,
responseBody
,
url
,
data
;
jQuery
(
document
).
slapos
();
module
(
"
Cross-domain Tests
"
);
module
(
"
Cross-domain Tests
"
);
test
(
"
200 response
"
,
function
(){
test
(
"
200 response
"
,
function
(){
...
@@ -33,6 +32,34 @@ jQuery(function(){
...
@@ -33,6 +32,34 @@ jQuery(function(){
}});
}});
});
});
module
(
"
Storage Test
"
,
{
setup
:
function
()
{
this
.
myhost
=
'
http://www.example.com/api
'
;
jQuery
(
document
).
slapos
({
'
host
'
:
this
.
myhost
});
}
});
test
(
""
,
function
()
{
expect
(
5
);
var
test
=
"
testValue
"
,
newToken
=
"
newToken
"
,
nnToken
=
""
;
equal
(
this
.
myhost
,
jQuery
(
document
).
slapos
(
'
host
'
),
"
should contain the same host when initialized
"
);
jQuery
(
document
).
slapos
(
'
store
'
,
'
test
'
,
test
);
equal
(
test
,
window
.
localStorage
.
test
,
'
should add new key "test" in local storage
'
);
jQuery
(
document
).
slapos
(
'
access_token
'
,
newToken
);
equal
(
newToken
,
window
.
localStorage
.
access_token
,
'
should add new key "access_token" by using its shortcut method
'
);
nnToken
=
jQuery
(
document
).
slapos
(
'
access_token
'
);
equal
(
nnToken
,
newToken
,
'
should put "newToken" value in nnToken
'
)
jQuery
(
document
).
slapos
(
'
deleteStore
'
,
'
access_token
'
);
ok
(
window
.
localStorage
.
getItem
(
'
access_token
'
)
===
null
,
'
should delete "access_token" from localStorage
'
);
});
module
(
"
Callback Tests
"
,
{
module
(
"
Callback Tests
"
,
{
setup
:
function
(){
setup
:
function
(){
this
.
server
=
sinon
.
sandbox
.
useFakeServer
();
this
.
server
=
sinon
.
sandbox
.
useFakeServer
();
...
@@ -57,7 +84,7 @@ jQuery(function(){
...
@@ -57,7 +84,7 @@ jQuery(function(){
}
}
};
};
var
discoResponse
=
[
200
,
this
.
header
,
JSON
.
stringify
(
discoBody
)];
var
discoResponse
=
[
200
,
this
.
header
,
JSON
.
stringify
(
discoBody
)];
this
.
server
.
respondWith
(
"
GET
"
,
'
http://10.8.2.34:12006/erp5/portal_vifib_rest_api_v1
'
,
discoResponse
);
this
.
server
.
respondWith
(
"
GET
"
,
'
/api
'
,
discoResponse
);
// Error responses
// Error responses
this
.
bad_request
=
[
400
,
this
.
header
,
'
Bad Request
'
];
this
.
bad_request
=
[
400
,
this
.
header
,
'
Bad Request
'
];
...
@@ -65,6 +92,8 @@ jQuery(function(){
...
@@ -65,6 +92,8 @@ jQuery(function(){
this
.
payment
=
[
402
,
this
.
header
,
'
Payment required
'
];
this
.
payment
=
[
402
,
this
.
header
,
'
Payment required
'
];
this
.
not_found
=
[
404
,
this
.
header
,
'
Not found
'
];
this
.
not_found
=
[
404
,
this
.
header
,
'
Not found
'
];
this
.
server_error
=
[
500
,
this
.
header
,
'
Internal server error
'
];
this
.
server_error
=
[
500
,
this
.
header
,
'
Internal server error
'
];
jQuery
(
document
).
slapos
({
'
host
'
:
'
/api
'
});
},
},
teardown
:
function
(){
teardown
:
function
(){
this
.
server
.
restore
();
this
.
server
.
restore
();
...
@@ -81,9 +110,10 @@ jQuery(function(){
...
@@ -81,9 +110,10 @@ jQuery(function(){
statusCode
=
{
statusCode
=
{
400
:
callback
400
:
callback
};
};
jQuery
(
document
).
slapos
(
'
instanceRequest
'
,
{
var
i
=
jQuery
(
document
).
slapos
(
'
instanceRequest
'
,
{
url
:
"
/request_instance
"
,
url
:
"
/request_instance
"
,
statusCode
:
statusCode
,
statusCode
:
statusCode
,
complete
:
function
()
{
start
()
}
});
});
this
.
server
.
respond
();
this
.
server
.
respond
();
});
});
...
@@ -101,6 +131,7 @@ jQuery(function(){
...
@@ -101,6 +131,7 @@ jQuery(function(){
jQuery
(
document
).
slapos
(
'
instanceRequest
'
,
{
jQuery
(
document
).
slapos
(
'
instanceRequest
'
,
{
url
:
"
/request_instance
"
,
url
:
"
/request_instance
"
,
statusCode
:
statusCode
,
statusCode
:
statusCode
,
complete
:
function
()
{
start
()
}
});
});
this
.
server
.
respond
();
this
.
server
.
respond
();
});
});
...
@@ -118,6 +149,7 @@ jQuery(function(){
...
@@ -118,6 +149,7 @@ jQuery(function(){
jQuery
(
document
).
slapos
(
'
instanceRequest
'
,
{
jQuery
(
document
).
slapos
(
'
instanceRequest
'
,
{
url
:
"
/request_instance
"
,
url
:
"
/request_instance
"
,
statusCode
:
statusCode
,
statusCode
:
statusCode
,
complete
:
function
()
{
start
()
}
});
});
this
.
server
.
respond
();
this
.
server
.
respond
();
});
});
...
@@ -135,6 +167,7 @@ jQuery(function(){
...
@@ -135,6 +167,7 @@ jQuery(function(){
jQuery
(
document
).
slapos
(
'
instanceRequest
'
,
{
jQuery
(
document
).
slapos
(
'
instanceRequest
'
,
{
url
:
"
/request_instance
"
,
url
:
"
/request_instance
"
,
statusCode
:
statusCode
,
statusCode
:
statusCode
,
complete
:
function
()
{
start
()
}
});
});
this
.
server
.
respond
();
this
.
server
.
respond
();
});
});
...
@@ -152,6 +185,7 @@ jQuery(function(){
...
@@ -152,6 +185,7 @@ jQuery(function(){
jQuery
(
document
).
slapos
(
'
instanceRequest
'
,
{
jQuery
(
document
).
slapos
(
'
instanceRequest
'
,
{
url
:
"
/request_instance
"
,
url
:
"
/request_instance
"
,
statusCode
:
statusCode
,
statusCode
:
statusCode
,
complete
:
function
()
{
start
()
}
});
});
this
.
server
.
respond
();
this
.
server
.
respond
();
});
});
...
...
vifib/static/js/core.js
View file @
406112e2
...
@@ -19,7 +19,6 @@
...
@@ -19,7 +19,6 @@
pattern
=
pattern
.
replace
(
/:
\w
+/g
,
'
([^
\
/]+)
'
);
pattern
=
pattern
.
replace
(
/:
\w
+/g
,
'
([^
\
/]+)
'
);
var
regex
=
new
RegExp
(
'
^
'
+
pattern
+
'
$
'
),
var
regex
=
new
RegExp
(
'
^
'
+
pattern
+
'
$
'
),
result
=
regex
.
exec
(
d
);
result
=
regex
.
exec
(
d
);
console
.
log
(
d
);
if
(
result
)
{
if
(
result
)
{
result
.
shift
();
result
.
shift
();
methods
[
callback
].
apply
(
$this
,
result
);
methods
[
callback
].
apply
(
$this
,
result
);
...
@@ -77,12 +76,12 @@
...
@@ -77,12 +76,12 @@
$
(
this
).
vifib
(
'
popup
'
,
message
);
$
(
this
).
vifib
(
'
popup
'
,
message
);
},
},
spinOptions
=
{
color
:
'
#FFF
'
,
lines
:
9
,
length
:
3
,
width
:
2
,
radius
:
6
,
rotate
:
0
,
trail
:
36
,
speed
:
1.0
},
spinOptions
=
{
color
:
"
#FFFFFF
"
,
lines
:
30
,
length
:
0
,
width
:
5
,
radius
:
7
,
rotate
:
0
,
trail
:
60
,
speed
:
1.6
},
methods
=
{
methods
=
{
init
:
function
()
{
init
:
function
()
{
// Initialize slapos in this context
// Initialize slapos in this context
$
(
this
).
slapos
();
$
(
this
).
slapos
(
{
'
host
'
:
'
http://10.8.2.34:12006/erp5/portal_vifib_rest_api_v1
'
}
);
var
$this
=
$
(
this
);
var
$this
=
$
(
this
);
// Bind Loading content
// Bind Loading content
$
(
'
#loading
'
).
ajaxStart
(
function
()
{
$
(
'
#loading
'
).
ajaxStart
(
function
()
{
...
@@ -110,8 +109,9 @@
...
@@ -110,8 +109,9 @@
},
},
extractInstanceURIFromHashtag
:
function
()
{
extractInstanceURIFromHashtag
:
function
()
{
var
loc
=
window
.
location
.
h
ash
.
split
(
'
/
'
),
var
loc
=
window
.
location
.
h
ref
.
split
(
'
#
'
)[
1
]
.
split
(
'
/
'
),
i
=
$
.
inArray
(
"
instance
"
,
loc
);
i
=
$
.
inArray
(
"
instance
"
,
loc
);
console
.
log
(
loc
)
return
(
i
!==
-
1
&&
loc
.
length
>
i
)
?
decodeURIComponent
(
loc
[
i
+
1
])
:
""
;
return
(
i
!==
-
1
&&
loc
.
length
>
i
)
?
decodeURIComponent
(
loc
[
i
+
1
])
:
""
;
},
},
...
@@ -180,12 +180,12 @@
...
@@ -180,12 +180,12 @@
return
this
.
each
(
function
()
{
return
this
.
each
(
function
()
{
var
uri
=
$
(
this
).
vifib
(
"
extractInstanceURIFromHashtag
"
);
var
uri
=
$
(
this
).
vifib
(
"
extractInstanceURIFromHashtag
"
);
$
(
this
).
slapos
(
'
instanceInfo
'
,
uri
,
{
$
(
this
).
slapos
(
'
instanceInfo
'
,
uri
,
{
success
:
function
(
data
)
{
success
:
function
(
response
)
{
if
(
typeof
(
data
)
!==
"
object
"
)
{
if
(
typeof
(
response
)
!==
"
object
"
)
{
data
=
$
.
parseJSON
(
data
);
response
=
$
.
parseJSON
(
response
);
}
}
var
status
=
$
(
this
).
vifib
(
'
getRender
'
,
'
instance.
'
+
data
.
status
)
var
status
=
$
(
this
).
vifib
(
'
getRender
'
,
'
instance.
'
+
response
.
status
)
$
(
"
[name=software_type]
"
).
val
(
data
.
software_type
);
$
(
"
[name=software_type]
"
).
val
(
response
.
software_type
);
$
(
"
#instanceStatus
"
).
html
(
status
);
$
(
"
#instanceStatus
"
).
html
(
status
);
$
(
this
).
vifib
(
'
bindStopStartButtons
'
);
$
(
this
).
vifib
(
'
bindStopStartButtons
'
);
}
}
...
@@ -299,7 +299,7 @@
...
@@ -299,7 +299,7 @@
503
:
serverError
503
:
serverError
},
},
table
=
$
(
this
).
vifib
(
'
render
'
,
'
instance.list
'
).
find
(
'
#instance-table
'
);
table
=
$
(
this
).
vifib
(
'
render
'
,
'
instance.list
'
).
find
(
'
#instance-table
'
);
//
table.vifib('refresh', methods.refreshListInstance, 30);
table
.
vifib
(
'
refresh
'
,
methods
.
refreshListInstance
,
30
);
$
(
this
).
slapos
(
'
instanceList
'
,
{
$
(
this
).
slapos
(
'
instanceList
'
,
{
success
:
function
(
data
)
{
success
:
function
(
data
)
{
if
(
typeof
(
data
)
!==
"
object
"
)
{
if
(
typeof
(
data
)
!==
"
object
"
)
{
...
@@ -308,7 +308,7 @@
...
@@ -308,7 +308,7 @@
$
.
each
(
data
.
list
,
function
()
{
$
.
each
(
data
.
list
,
function
()
{
var
url
=
this
.
toString
(),
var
url
=
this
.
toString
(),
row
=
$
(
'
<tr></tr>
'
).
vifib
(
'
fillRowInstance
'
,
url
);
row
=
$
(
'
<tr></tr>
'
).
vifib
(
'
fillRowInstance
'
,
url
);
//
row.vifib('refresh', methods.refreshRowInstance, 30);
row
.
vifib
(
'
refresh
'
,
methods
.
refreshRowInstance
,
30
);
table
.
append
(
row
);
table
.
append
(
row
);
});
});
},
},
...
...
vifib/static/js/jquery.slapos.js
View file @
406112e2
...
@@ -27,6 +27,10 @@
...
@@ -27,6 +27,10 @@
return
$
(
this
).
slapos
(
'
store
'
,
'
clientID
'
,
value
);
return
$
(
this
).
slapos
(
'
store
'
,
'
clientID
'
,
value
);
},
},
deleteStore
:
function
(
name
)
{
delete
window
.
localStorage
[
name
];
},
/* Local storage method */
/* Local storage method */
lStore
:
function
(
name
,
value
)
{
lStore
:
function
(
name
,
value
)
{
if
(
Modernizr
.
localstorage
)
{
if
(
Modernizr
.
localstorage
)
{
...
@@ -82,10 +86,10 @@
...
@@ -82,10 +86,10 @@
datatype
:
'
json
'
,
datatype
:
'
json
'
,
context
:
$
(
this
),
context
:
$
(
this
),
beforeSend
:
function
(
xhr
)
{
beforeSend
:
function
(
xhr
)
{
//
xhr.setRequestHeader('REMOTE_USER', 'test_vifib_customer');
xhr
.
setRequestHeader
(
'
REMOTE_USER
'
,
'
test_vifib_customer
'
);
xhr
.
setRequestHeader
(
'
Accept
'
,
'
application/json
'
);
xhr
.
setRequestHeader
(
'
Accept
'
,
'
application/json
'
);
if
(
$
(
this
).
slapos
(
'
access_token
'
)
&&
authentication
)
{
if
(
$
(
this
).
slapos
(
'
access_token
'
)
&&
authentication
)
{
xhr
.
setRequestHeader
(
'
Authorization
'
,
$
(
this
).
slapos
(
'
store
'
,
'
token_type
'
)
+
'
'
+
$
(
this
).
slapos
(
'
access_token
'
));
//
xhr.setRequestHeader('Authorization', $(this).slapos('store', 'token_type') + ' ' + $(this).slapos('access_token'));
}
}
}
}
};
};
...
@@ -116,7 +120,8 @@
...
@@ -116,7 +120,8 @@
discovery
:
function
(
callback
)
{
discovery
:
function
(
callback
)
{
return
this
.
each
(
function
()
{
return
this
.
each
(
function
()
{
$
.
ajax
({
$
.
ajax
({
url
:
'
http://10.8.2.34:12006/erp5/portal_vifib_rest_api_v1
'
,
url
:
$
(
this
).
slapos
(
"
host
"
),
context
:
$
(
this
),
dataType
:
'
json
'
,
dataType
:
'
json
'
,
beforeSend
:
function
(
xhr
)
{
beforeSend
:
function
(
xhr
)
{
xhr
.
setRequestHeader
(
'
Accept
'
,
'
application/json
'
);
xhr
.
setRequestHeader
(
'
Accept
'
,
'
application/json
'
);
...
...
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