Commit 7576610c authored by Alexandra Rogova's avatar Alexandra Rogova

saving works, now working on queries

parent a404e13f
......@@ -17,17 +17,6 @@
this.sub_storages = [];
/*this.search_storage = jIO.createJIO({
type : "query",
sub_storage:{
type : "uuid",
sub_storage : {
type: "indexeddb",
database: "mynij-v1"
}
}
});*/
this.info = jIO.createJIO({
type : "indexeddb",
database : "mynij-v1-info"
......@@ -37,9 +26,10 @@
})
.declareMethod ("add_attachment", function (title, rss){
var gadget = this;
return this.feeds.putAttachment("feeds_doc", title, new Blob([rss], {type : "text/xml"}))
.push(function (){
this.sub_storages.push({
var new_sub_storage = {
type : "my_parser",
document_id : "feeds_doc",
attachment_id : title,
......@@ -48,18 +38,15 @@
type : "indexeddb",
database : "mynij-v1.2"
}
});
this.search_storage = jIO.createJIO({
}
gadget.sub_storages.push(new_sub_storage);
gadget.search_storage = jIO.createJIO({
type : "union",
storage_list : this.sub_storages
storage_list : gadget.sub_storages
});
});
})
.declareMethod("put", function () { // deprecated
return this.search_storage.post.apply(this.search_storage, arguments);
})
.declareMethod("get", function () {
return this.search_storage.get.apply(this.search_storage, arguments);
})
......
......@@ -6,43 +6,35 @@
.declareAcquiredMethod("get_model", "get_model")
.setState({
storage : null
})
.ready(function(){
var gadget = this;
.declareMethod("read_file_new", function(link){
var gadget = this,
storage;
return gadget.get_model()
.push(function(result){
return gadget.changeState({
storage : result
});
});
})
.declareMethod("read_file_new", function(link){
var gadget = this,
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.status == 200 && xmlhttp.readyState == 4){
var rss,
title;
rss = xmlhttp.responseText;
title = rss.slice(rss.indexOf("<title>")+7, rss.indexOf("</title>"));
return gadget.is_already_parsed(title)
.push(function(is_parsed){
if (!is_parsed){
return gadget.remove_css(rss)
.push(function(rss_without_css){
return gadget.state.storage.add_attachment(title, rss_without_css);
});
}
});
}
}
xmlhttp.open("GET", link, true);
xmlhttp.send();
storage = result;
})
.push (function(){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.status == 200 && xmlhttp.readyState == 4){
var rss,
title;
rss = xmlhttp.responseText;
title = rss.slice(rss.indexOf("<title>")+7, rss.indexOf("</title>"));
return gadget.is_already_loaded(title)
.push(function(is_loaded){
if (!is_loaded){
return gadget.remove_css(rss)
.push(function(rss_without_css){
return storage.add_attachment(title, rss_without_css);
});
}
});
}
};
xmlhttp.open("GET", link, true);
xmlhttp.send();
});
})
.declareMethod("remove_css", function(body){
......@@ -50,8 +42,11 @@
return body.replace(regEx, "");
})
.declareMethod("is_already_parsed", function(title){
return this.state.storage.all_loaded_docs()
.declareMethod("is_already_loaded", function(title){
return this.get_model()
.push(function(storage){
return storage.all_loaded_docs();
})
.push(function (result){
var i;
for (i = 0; i<result.data.rows.length; i+=1){
......
......@@ -4,6 +4,7 @@
<title>Mynij</title>
<script src="../jio/external/rsvp-2.0.4.js"></script>
<script src="../jio/dist/jio-latest.js"></script>
<script src="jio.my_parser_storage.js"></script>
<script src="../renderjs/dist/renderjs-latest.js"></script>
<script src="search.js"></script>
<link rel="stylesheet" type="text/css" href="mynij.css">
......
......@@ -23,10 +23,6 @@
]
})
.allowPublicAcquisition("get_model", function(){
return this.getDeclaredGadget("model");
})
.ready(function(){
var model_gadget,
result_gadget;
......@@ -64,9 +60,17 @@
}
RSVP.all(promise_list);
})
.allowPublicAcquisition("get_model", function(){
return this.getDeclaredGadget("model");
})
.declareMethod("search", function (key){
var gadget = this,
return this.state.model_gadget.search()
.push(function (result){
console.log(result);
})
/*var gadget = this,
options;
options = {
......@@ -102,7 +106,7 @@
promise_list.push(gadget.state.result_gadget.addItem(result_list[j], key));
}
return RSVP.all(promise_list);
});
});*/
})
.onEvent("submit", function(event){
......
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