Commit b2fba5af authored by Tristan Cavelier's avatar Tristan Cavelier Committed by Sebastien Robin

Jio doesn't browse all localStorage anymore.

parent a7cb5e61
......@@ -29,14 +29,20 @@
<script id="login" type="text/html">
<article>
<div class="control-group">
<label class="control-label" for="input_json_storage">JSON Storage</label>
<label class="control-label"
for="input_json_storage">
JSON Storage
</label>
<div class="controls docs-input-sizes">
<input class="input-xlarge"
type="text" name="JSONstorage" id="input_json_storage"
value="{&quot;type&quot;:&quot;local&quot;,&quot;userName&quot;:&quot;tristan&quot;}"
placeholder="storage" />
</div>
<label class="control-label" for="JSONapplicantID">JSON Applicant</label>
<label class="control-label"
for="JSONapplicantID">
JSON Applicant
</label>
<div class="controls docs-input-sizes">
<input class="input-xlarge"
type="text" name="JSONapplicant" id="input_json_applicant"
......@@ -44,7 +50,9 @@
placeholder="applicant" />
</div>
</div>
<button type="submit" class="btn" onclick="OfficeJS.setJio()">Create New JIO</button>
<button type="submit"
class="btn"
onclick="OfficeJS.setJio()">Create New JIO</button>
</article>
</script>
<script id="text_editor" type="text/html">
......@@ -60,10 +68,30 @@
<input type="text" name="fileContent" id="input_content"
value="" placeholder="content" />
</div>
<button type="submit" class="btn btn-primary" onclick="OfficeJS.save()"><i class="icon-download-alt icon-white"></i> Save</button>&nbsp;
<button type="submit" class="btn" onclick="OfficeJS.load()"><i class="icon-upload"></i> Load</button>&nbsp;
<button type="submit" class="btn btn-danger" onclick="OfficeJS.remove()"><i class="icon-remove icon-white"></i> Remove</button>&nbsp;
<button type="submit" class="btn" onclick="OfficeJS.getlist()"><i class="icon-refresh"></i> Get List</button>&nbsp;
<button type="submit"
class="btn btn-primary"
onclick="OfficeJS.save()">
<i class="icon-download-alt icon-white"></i>
Save
</button>&nbsp;
<button type="submit"
class="btn"
onclick="OfficeJS.load()">
<i class="icon-upload"></i>
Load
</button>&nbsp;
<button type="submit"
class="btn btn-danger"
onclick="OfficeJS.remove()">
<i class="icon-remove icon-white"></i>
Remove
</button>&nbsp;
<button type="submit"
class="btn"
onclick="OfficeJS.getlist()">
<i class="icon-refresh"></i>
Get List
</button>&nbsp;
</div>
<div id="document_list" class="span4">
<ul>
......@@ -105,7 +133,9 @@
<li class="nav-header">Nav</li>
<li><a href="#/login"><i class="icon-ok"></i>Login</a></li>
<li class="nav-header">Documents</li>
<li class="texteditor"><a href="#/texteditor"><i class="icon-font"></i>Text Editor</a></li>
<li class="texteditor">
<a href="#/texteditor"><i class="icon-font"></i>Text Editor</a>
</li>
</ul>
</div>
</div>
......
......@@ -249,20 +249,27 @@ var JIO =
// options.useLocalStorage: if true, save jobs into localStorage,
// else only save on memory.
var that = {}, priv = {};
var that = {}, priv = {},
jioIdArrayName = 'jio/idArray';
that.init = function ( options ) {
// initialize the JobQueue
// options.publisher : is the publisher to use to send events
// options.jioID : the jio ID
var k, emptyfun = function (){};
var k, emptyfun = function (){},
jioIdArray = jioGlobalObj.localStorage.getItem (jioIdArrayName);
if (jioIdArray === null) {
jioIdArray = [];
}
if (options.publisher) {
priv.publisher = publisher;
}
priv.jioID = options.jioID;
priv.jobObjectName = 'jio/jobObject/'+options.jioID;
priv.jobObject = {};
jioIdArray.push (priv.jioID);
jioGlobalObj.localStorage.setItem (jioIdArrayName,jioIdArray);
that.copyJobQueueToLocalStorage();
for (k in priv.recoveredJobObject) {
priv.recoveredJobObject[k].callback = emptyfun;
......@@ -280,15 +287,12 @@ var JIO =
};
that.getNewQueueID = function () {
// Returns a new queueID
var localStorageObject = jioGlobalObj.localStorage.getAll(),
id = 0, k = 'key', splitk = ['splitedkey'];
for (k in localStorageObject) {
splitk = k.split('/');
if (splitk[0] === 'jio' &&
splitk[1] === 'id') {
if (JSON.parse(splitk[2]) >= jioGlobalObj.queueID) {
jioGlobalObj.queueID = JSON.parse(splitk[2]) + 1;
}
var k = null, id = 0,
jioIdArray = jioGlobalObj.localStorage.getItem (jioIdArrayName);
for (k in jioIdArray) {
if (jioIdArray[k] >= jioGlobalObj.queueID) {
jioGlobalObj.queueID = jioIdArray[k] + 1;
}
}
id = jioGlobalObj.queueID;
......@@ -298,23 +302,29 @@ var JIO =
that.recoverOlderJobObject = function () {
// recover job object from older inactive jio
var localStorageObject = jioGlobalObj.localStorage.getAll(),
k = 'key', splitk = ['splitedkey'];
for (k in localStorageObject) {
splitk = k.split('/');
if (splitk[0] === 'jio' &&
splitk[1] === 'id' ) {
if (localStorageObject[k] < Date.now() - 10000){
// 10 sec ? delete item
jioGlobalObj.localStorage.deleteItem(k);
var k = null, newJioIdArray = [], jioIdArrayChanged = false,
jioIdArray = jioGlobalObj.localStorage.getItem (jioIdArrayName);
for (k in jioIdArray) {
if (jioGlobalObj.localStorage.getItem (
'jio/id/'+jioIdArray[k]) < Date.now () - 10000) {
// remove id from jioIdArray
// 10000 sec ? delete item
jioGlobalObj.localStorage.deleteItem('jio/id/'+
jioIdArray[k]);
// job recovery
priv.recoveredJobObject = jioGlobalObj.
localStorage.getItem('jio/jioObject/'+splitk[2]);
localStorage.getItem('jio/jioObject/'+ jioIdArray[k]);
// remove ex job object
jioGlobalObj.localStorage.deleteItem(
'jio/jobObject/'+splitk[2]);
'jio/jobObject/'+ jioIdArray[k]);
jioIdArrayChanged = true;
} else {
newJioIdArray.push (jioIdArray[k]);
}
}
if (jioIdArrayChanged) {
jioGlobalObj.localStorage.setItem(jioIdArrayName,newJioIdArray);
}
};
that.isThereJobsWhere = function( func ) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment