Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
lucas.parsy
jio
Commits
1527f4a9
Commit
1527f4a9
authored
Jan 10, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jslint pass storage.js
parent
ac79eed3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
192 additions
and
189 deletions
+192
-189
src/jio/storages/storage.js
src/jio/storages/storage.js
+192
-189
No files found.
src/jio/storages/storage.js
View file @
1527f4a9
var
storage
=
function
(
spec
,
my
)
{
/*jslint indent: 2, maxlen: 80, sloppy: true */
var
that
=
{};
/*global command: true, jobManager: true, job: true */
spec
=
spec
||
{};
var
storage
=
function
(
spec
,
my
)
{
my
=
my
||
{};
var
that
=
{},
priv
=
{};
// Attributes //
spec
=
spec
||
{};
var
priv
=
{};
my
=
my
||
{};
priv
.
type
=
spec
.
type
||
''
;
// Attributes //
priv
.
type
=
spec
.
type
||
''
;
// Methods //
Object
.
defineProperty
(
that
,
"
getType
"
,{
// Methods //
configurable
:
false
,
enumerable
:
false
,
writable
:
false
,
value
:
Object
.
defineProperty
(
that
,
"
getType
"
,
{
function
()
{
configurable
:
false
,
return
priv
.
type
;
enumerable
:
false
,
}
writable
:
false
,
value
:
function
()
{
return
priv
.
type
;
}
});
/**
* Execute the command on this storage.
* @method execute
* @param {object} command The command
*/
that
.
execute
=
function
(
command
)
{
that
.
success
=
command
.
success
;
that
.
error
=
command
.
error
;
that
.
retry
=
command
.
retry
;
that
.
end
=
command
.
end
;
if
(
that
.
validate
(
command
))
{
command
.
executeOn
(
that
);
}
};
/**
* Override this function to validate specifications.
* @method isValid
* @return {boolean} true if ok, else false.
*/
that
.
isValid
=
function
()
{
return
true
;
};
that
.
validate
=
function
()
{
var
mess
=
that
.
validateState
();
if
(
mess
)
{
that
.
error
({
"
status
"
:
0
,
"
statusText
"
:
"
Invalid Storage
"
,
"
error
"
:
"
invalid_storage
"
,
"
message
"
:
mess
,
"
reason
"
:
mess
});
return
false
;
}
return
true
;
};
/**
* Returns a serialized version of this storage.
* @method serialized
* @return {object} The serialized storage.
*/
that
.
serialized
=
function
()
{
var
o
=
that
.
specToStore
()
||
{};
o
.
type
=
that
.
getType
();
return
o
;
};
/**
* Returns an object containing spec to store on localStorage, in order to
* be restored later if something wrong happen.
* Override this method!
* @method specToStore
* @return {object} The spec to store
*/
that
.
specToStore
=
function
()
{
return
{};
};
/**
* Validate the storage state. It returns a empty string all is ok.
* @method validateState
* @return {string} empty: ok, else error message.
*/
that
.
validateState
=
function
()
{
return
''
;
};
that
.
post
=
function
()
{
setTimeout
(
function
()
{
that
.
error
({
"
status
"
:
0
,
"
statusText
"
:
"
Not Implemented
"
,
"
error
"
:
"
not_implemented
"
,
"
message
"
:
"
\"
Post
\"
command is not implemented
"
,
"
reason
"
:
"
Command not implemented
"
});
});
});
};
/**
* Execute the command on this storage.
that
.
put
=
function
()
{
* @method execute
setTimeout
(
function
()
{
* @param {object} command The command
that
.
error
({
*/
"
status
"
:
0
,
that
.
execute
=
function
(
command
)
{
"
statusText
"
:
"
Not Implemented
"
,
that
.
success
=
command
.
success
;
"
error
"
:
"
not_implemented
"
,
that
.
error
=
command
.
error
;
"
message
"
:
"
\"
Put
\"
command is not implemented
"
,
that
.
retry
=
command
.
retry
;
"
reason
"
:
"
Command not implemented
"
that
.
end
=
command
.
end
;
});
if
(
that
.
validate
(
command
))
{
});
command
.
executeOn
(
that
);
};
}
};
that
.
putAttachment
=
function
()
{
setTimeout
(
function
()
{
/**
that
.
error
({
* Override this function to validate specifications.
"
status
"
:
0
,
* @method isValid
"
statusText
"
:
"
Not Implemented
"
,
* @return {boolean} true if ok, else false.
"
error
"
:
"
not_implemented
"
,
*/
"
message
"
:
"
\"
PutAttachment
\"
command is not implemented
"
,
that
.
isValid
=
function
()
{
"
reason
"
:
"
Command not implemented
"
return
true
;
});
};
});
};
that
.
validate
=
function
()
{
var
mess
=
that
.
validateState
();
that
.
get
=
function
()
{
if
(
mess
)
{
setTimeout
(
function
()
{
that
.
error
({
that
.
error
({
status
:
0
,
statusText
:
'
Invalid Storage
'
,
"
status
"
:
0
,
error
:
'
invalid_storage
'
,
"
statusText
"
:
"
Not Implemented
"
,
message
:
mess
,
reason
:
mess
"
error
"
:
"
not_implemented
"
,
});
"
message
"
:
"
\"
Get
\"
command is not implemented
"
,
return
false
;
"
reason
"
:
"
Command not implemented
"
}
});
return
true
;
});
};
};
/**
that
.
allDocs
=
function
()
{
* Returns a serialized version of this storage.
setTimeout
(
function
()
{
* @method serialized
that
.
error
({
* @return {object} The serialized storage.
"
status
"
:
0
,
*/
"
statusText
"
:
"
Not Implemented
"
,
that
.
serialized
=
function
()
{
"
error
"
:
"
not_implemented
"
,
var
o
=
that
.
specToStore
()
||
{};
"
message
"
:
"
\"
AllDocs
\"
command is not implemented
"
,
o
[
"
type
"
]
=
that
.
getType
();
"
reason
"
:
"
Command not implemented
"
return
o
;
});
};
});
};
/**
* Returns an object containing spec to store on localStorage, in order to
that
.
remove
=
function
()
{
* be restored later if something wrong happen.
setTimeout
(
function
()
{
* Override this method!
that
.
error
({
* @method specToStore
"
status
"
:
0
,
* @return {object} The spec to store
"
statusText
"
:
"
Not Implemented
"
,
*/
"
error
"
:
"
not_implemented
"
,
that
.
specToStore
=
function
()
{
"
message
"
:
"
\"
Remove
\"
command is not implemented
"
,
return
{};
"
reason
"
:
"
Command not implemented
"
};
});
});
/**
};
* Validate the storage state. It returns a empty string all is ok.
* @method validateState
that
.
success
=
function
()
{};
* @return {string} empty: ok, else error message.
that
.
retry
=
function
()
{};
*/
that
.
error
=
function
()
{};
that
.
validateState
=
function
()
{
that
.
end
=
function
()
{};
// terminate the current job.
return
''
;
};
priv
.
newCommand
=
function
(
method
,
spec
)
{
var
o
=
spec
||
{};
that
.
post
=
function
()
{
o
.
label
=
method
;
setTimeout
(
function
()
{
return
command
(
o
,
my
);
that
.
error
({
};
"
status
"
:
0
,
"
statusText
"
:
"
Not Implemented
"
,
priv
.
storage
=
my
.
storage
;
"
error
"
:
"
not_implemented
"
,
delete
my
.
storage
;
"
message
"
:
"
\"
Post
\"
command is not implemented
"
,
"
reason
"
:
"
Command not implemented
"
that
.
addJob
=
function
(
method
,
storage_spec
,
doc
,
option
,
success
,
error
)
{
});
var
command_opt
=
{
});
options
:
option
,
};
callbacks
:
{
success
:
success
,
error
:
error
}
that
.
put
=
function
()
{
setTimeout
(
function
()
{
that
.
error
({
"
status
"
:
0
,
"
statusText
"
:
"
Not Implemented
"
,
"
error
"
:
"
not_implemented
"
,
"
message
"
:
"
\"
Put
\"
command is not implemented
"
,
"
reason
"
:
"
Command not implemented
"
});
});
};
that
.
putAttachment
=
function
()
{
setTimeout
(
function
()
{
that
.
error
({
"
status
"
:
0
,
"
statusText
"
:
"
Not Implemented
"
,
"
error
"
:
"
not_implemented
"
,
"
message
"
:
"
\"
PutAttachment
\"
command is not implemented
"
,
"
reason
"
:
"
Command not implemented
"
});
});
};
that
.
get
=
function
()
{
setTimeout
(
function
()
{
that
.
error
({
"
status
"
:
0
,
"
statusText
"
:
"
Not Implemented
"
,
"
error
"
:
"
not_implemented
"
,
"
message
"
:
"
\"
Get
\"
command is not implemented
"
,
"
reason
"
:
"
Command not implemented
"
});
});
};
that
.
allDocs
=
function
()
{
setTimeout
(
function
()
{
that
.
error
({
"
status
"
:
0
,
"
statusText
"
:
"
Not Implemented
"
,
"
error
"
:
"
not_implemented
"
,
"
message
"
:
"
\"
AllDocs
\"
command is not implemented
"
,
"
reason
"
:
"
Command not implemented
"
});
});
};
that
.
remove
=
function
()
{
setTimeout
(
function
()
{
that
.
error
({
"
status
"
:
0
,
"
statusText
"
:
"
Not Implemented
"
,
"
error
"
:
"
not_implemented
"
,
"
message
"
:
"
\"
Remove
\"
command is not implemented
"
,
"
reason
"
:
"
Command not implemented
"
});
});
};
that
.
success
=
function
()
{};
that
.
retry
=
function
()
{};
that
.
error
=
function
()
{};
that
.
end
=
function
()
{};
// terminate the current job.
priv
.
newCommand
=
function
(
method
,
spec
)
{
var
o
=
spec
||
{};
o
.
label
=
method
;
return
command
(
o
,
my
);
};
priv
.
storage
=
my
.
storage
;
delete
my
.
storage
;
that
.
addJob
=
function
(
method
,
storage_spec
,
doc
,
option
,
success
,
error
)
{
var
command_opt
=
{
options
:
option
,
callbacks
:{
success
:
success
,
error
:
error
}
};
if
(
doc
)
{
if
(
method
===
'
get
'
)
{
command_opt
.
docid
=
doc
;
}
else
{
command_opt
.
doc
=
doc
;
}
}
jobManager
.
addJob
(
job
({
storage
:
priv
.
storage
(
storage_spec
||
{}),
command
:
priv
.
newCommand
(
method
,
command_opt
)
},
my
)
);
};
};
if
(
doc
)
{
return
that
;
if
(
method
===
'
get
'
)
{
command_opt
.
docid
=
doc
;
}
else
{
command_opt
.
doc
=
doc
;
}
}
jobManager
.
addJob
(
job
({
storage
:
priv
.
storage
(
storage_spec
||
{}),
command
:
priv
.
newCommand
(
method
,
command_opt
)
},
my
));
};
return
that
;
};
};
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