Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Roque
jio
Commits
14aa39ea
Commit
14aa39ea
authored
Jan 10, 2013
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jslint pass command.js (2indent)
parent
fbdf009d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
283 additions
and
289 deletions
+283
-289
src/jio/commands/command.js
src/jio/commands/command.js
+283
-289
No files found.
src/jio/commands/command.js
View file @
14aa39ea
var
command
=
function
(
spec
,
my
)
{
var
that
=
{};
// -*- jslint: --nomen --todo --maxlen 80 -*-
var
command
=
function
(
spec
,
my
)
{
var
that
=
{},
priv
=
{};
spec
=
spec
||
{};
my
=
my
||
{};
// Attributes //
var
priv
=
{};
priv
.
commandlist
=
{
'
post
'
:
postCommand
,
'
put
'
:
putCommand
,
'
get
'
:
getCommand
,
'
remove
'
:
removeCommand
,
'
allDocs
'
:
allDocsCommand
,
'
putAttachment
'
:
putAttachmentCommand
'
post
'
:
postCommand
,
'
put
'
:
putCommand
,
'
get
'
:
getCommand
,
'
remove
'
:
removeCommand
,
'
allDocs
'
:
allDocsCommand
,
'
putAttachment
'
:
putAttachmentCommand
};
// creates the good command thanks to his label
if
(
spec
.
label
&&
priv
.
commandlist
[
spec
.
label
])
{
...
...
@@ -22,20 +24,25 @@ var command = function(spec, my) {
priv
.
tried
=
0
;
priv
.
doc
=
spec
.
doc
||
{};
if
(
typeof
priv
.
doc
!==
"
object
"
)
{
priv
.
doc
=
{
"
_id
"
:
priv
.
doc
.
toString
()};
priv
.
doc
=
{
"
_id
"
:
priv
.
doc
.
toString
()
};
}
priv
.
docid
=
spec
.
docid
||
priv
.
doc
.
_id
;
priv
.
option
=
spec
.
options
||
{};
priv
.
callbacks
=
spec
.
callbacks
||
{};
priv
.
success
=
priv
.
callbacks
.
success
||
function
()
{};
priv
.
error
=
priv
.
callbacks
.
error
||
function
()
{};
priv
.
retry
=
function
()
{
priv
.
success
=
priv
.
callbacks
.
success
||
function
()
{};
priv
.
error
=
priv
.
callbacks
.
error
||
function
()
{};
priv
.
retry
=
function
()
{
that
.
error
({
status
:
13
,
statusText
:
'
Fail Retry
'
,
error
:
'
fail_retry
'
,
message
:
'
Impossible to retry.
'
,
reason
:
'
Impossible to retry.
'
status
:
13
,
statusText
:
'
Fail Retry
'
,
error
:
'
fail_retry
'
,
message
:
'
Impossible to retry.
'
,
reason
:
'
Impossible to retry.
'
});
};
priv
.
end
=
function
()
{};
priv
.
end
=
function
()
{};
priv
.
on_going
=
false
;
// Methods //
...
...
@@ -46,10 +53,10 @@ var command = function(spec, my) {
*/
that
.
serialized
=
function
()
{
var
o
=
{};
o
[
"
label
"
]
=
that
.
getLabel
();
o
[
"
tried
"
]
=
priv
.
tried
;
o
[
"
doc
"
]
=
that
.
cloneDoc
();
o
[
"
option
"
]
=
that
.
cloneOption
();
o
.
label
=
that
.
getLabel
();
o
.
tried
=
priv
.
tried
;
o
.
doc
=
that
.
cloneDoc
();
o
.
option
=
that
.
cloneOption
();
return
o
;
};
...
...
@@ -58,7 +65,7 @@ var command = function(spec, my) {
* @method getLabel
* @return {string} The label.
*/
that
.
getLabel
=
function
()
{
that
.
getLabel
=
function
()
{
return
'
command
'
;
};
...
...
@@ -91,7 +98,7 @@ var command = function(spec, my) {
* @method getDoc
* @return {object} The document.
*/
that
.
getDoc
=
function
()
{
that
.
getDoc
=
function
()
{
return
priv
.
doc
;
};
...
...
@@ -157,12 +164,13 @@ var command = function(spec, my) {
*/
that
.
validate
=
function
(
storage
)
{
if
(
typeof
priv
.
docid
===
"
string
"
&&
!
priv
.
docid
.
match
(
/^
[^\/]
+
([\/][^\/]
+
)?
$/
))
{
!
priv
.
docid
.
match
(
"
^[^
\
/]+([
\
/][^
\
/]+)?$
"
))
{
that
.
error
({
status
:
21
,
statusText
:
'
Invalid Document Id
'
,
error
:
'
invalid_document_id
'
,
message
:
'
The document id must be like "abc" or "abc/def".
'
,
reason
:
'
The document id is no like "abc" or "abc/def"
'
status
:
21
,
statusText
:
'
Invalid Document Id
'
,
error
:
'
invalid_document_id
'
,
message
:
'
The document id must be like "abc" or "abc/def".
'
,
reason
:
'
The document id is no like "abc" or "abc/def"
'
});
return
false
;
}
...
...
@@ -175,7 +183,7 @@ var command = function(spec, my) {
/*
* Extend this function
*/
that
.
validateState
=
function
()
{
that
.
validateState
=
function
()
{
return
true
;
};
...
...
@@ -185,7 +193,7 @@ var command = function(spec, my) {
* @return {boolean} The result
*/
that
.
canBeRetried
=
function
()
{
return
(
typeof
priv
.
option
.
max_retry
===
'
undefined
'
||
return
(
priv
.
option
.
max_retry
===
undefined
||
priv
.
option
.
max_retry
===
0
||
priv
.
tried
<
priv
.
option
.
max_retry
);
};
...
...
@@ -195,7 +203,7 @@ var command = function(spec, my) {
* @method getTried
* @return {number} The number of time the command has been tried
*/
that
.
getTried
=
function
()
{
that
.
getTried
=
function
()
{
return
priv
.
tried
;
};
...
...
@@ -203,49 +211,43 @@ var command = function(spec, my) {
* Delegate actual excecution the storage.
* @param {object} storage The storage.
*/
that
.
execute
=
function
(
storage
)
{
that
.
execute
=
function
(
storage
)
{
if
(
!
priv
.
on_going
)
{
if
(
that
.
validate
(
storage
))
{
priv
.
tried
++
;
if
(
that
.
validate
(
storage
))
{
priv
.
tried
+=
1
;
priv
.
on_going
=
true
;
storage
.
execute
(
that
);
storage
.
execute
(
that
);
}
}
};
/**
* Execute the good method from the storage.
* Override this function.
* @method executeOn
* @param {object} storage The storage.
*/
that
.
executeOn
=
function
(
storage
)
{};
that
.
success
=
function
(
return_value
)
{
that
.
executeOn
=
function
(
storage
)
{};
that
.
success
=
function
(
return_value
)
{
priv
.
on_going
=
false
;
priv
.
success
(
return_value
);
priv
.
success
(
return_value
);
priv
.
end
(
doneStatus
());
};
that
.
retry
=
function
(
return_error
)
{
priv
.
on_going
=
false
;
if
(
that
.
canBeRetried
())
{
priv
.
retry
();
}
else
{
that
.
error
(
return_error
);
that
.
error
(
return_error
);
}
};
that
.
error
=
function
(
return_error
)
{
that
.
error
=
function
(
return_error
)
{
priv
.
on_going
=
false
;
priv
.
error
(
return_error
);
priv
.
end
(
failStatus
());
};
that
.
end
=
function
()
{
priv
.
end
(
doneStatus
());
};
that
.
onSuccessDo
=
function
(
fun
)
{
if
(
fun
)
{
priv
.
success
=
fun
;
...
...
@@ -253,7 +255,6 @@ var command = function(spec, my) {
return
priv
.
success
;
}
};
that
.
onErrorDo
=
function
(
fun
)
{
if
(
fun
)
{
priv
.
error
=
fun
;
...
...
@@ -261,24 +262,20 @@ var command = function(spec, my) {
return
priv
.
error
;
}
};
that
.
onEndDo
=
function
(
fun
)
{
priv
.
end
=
fun
;
};
that
.
onRetryDo
=
function
(
fun
)
{
priv
.
retry
=
fun
;
};
/**
* Is the command can be restored by another JIO : yes.
* @method canBeRestored
* @return {boolean} true
*/
that
.
canBeRestored
=
function
()
{
that
.
canBeRestored
=
function
()
{
return
true
;
};
/**
* Clones the command and returns it.
* @method clone
...
...
@@ -287,7 +284,6 @@ var command = function(spec, my) {
that
.
clone
=
function
()
{
return
command
(
that
.
serialized
(),
my
);
};
/**
* Clones the command options and returns the clone version.
* @method cloneOption
...
...
@@ -296,7 +292,6 @@ var command = function(spec, my) {
that
.
cloneOption
=
function
()
{
return
JSON
.
parse
(
JSON
.
stringify
(
priv
.
option
));
};
/**
* Clones the document and returns the clone version.
* @method cloneDoc
...
...
@@ -305,6 +300,5 @@ var command = function(spec, my) {
that
.
cloneDoc
=
function
()
{
return
JSON
.
parse
(
JSON
.
stringify
(
priv
.
doc
));
};
return
that
;
};
\ No newline at end of file
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