Commit 22007610 authored by Alexandra Rogova's avatar Alexandra Rogova

list of rss files to read in search.js

parent fd43ee53
(function (window, document, rJS, RSVP) {
var gadget;
rJS(window)
.setState({
counter: 0,
model_gadget : null,
parser_gadget : null,
result_gadget : null
})
.allowPublicAcquisition("get_model", function(){
return this.getDeclaredGadget("model");
})
.allowPublicAcquisition("get_counter", function(){
counter += 1;
return counter;
})
.ready(function(){
var model_gadget,
result_gadget;
console.log("ready !");
counter = 0;
var gadget = this;
return gadget.getDeclaredGadget("model")
.push(function(model){
model_gadget = model;
})
.push(function(){
return gadget.getDeclaredGadget("result");
})
.push(function(result){
result_gadget = result;
})
.push(function(){
return gadget.getDeclaredGadget("parser");
})
.push(function(result){
return gadget.changeState({
model_gadget : model_gadget,
parser_gadget : result,
result_gadget : result_gadget
});
});
})
.onStateChange(function (modification_dict){
var gadget = this;
return new RSVP.Queue()
.push(function (){
gadget.state.parser_gadget.readFile("../rss-files/vivelessvt.rss");
})
.push (function (result) {
gadget.state.parser_gadget.readFile("../rss-files/italienfacile.rss");
})
.push (function (result) {}, function (err) {
console.warn(error);
throw(error);
});
})
.declareMethod("search", function (key){
var gadget = this,
options;
options = {
query:'(title:"% '+key+' %") OR (title:"'+key+' %")OR (body:"% '+key+' %")'
};
return gadget.state.result_gadget.clear()
.push(function(){
return gadget.state.model_gadget.search(options);
})
.push (function(result){
if (result.data.rows.length === 0){
return gadget.state.result_gadget.addItem({
title : "No results found",
link : ""
});
}
var i,
id,
promise_list = [];
for (i = 0; i < result.data.rows.length; i+=1){
id = result.data.rows[i].id;
promise_list.push(gadget.state.model_gadget.get(id));
console.log(id);
}
return RSVP.all(promise_list);
})
.push(function(result_list){
var j,
promise_list = [];
for (j = 0; j < result_list.length; j+=1){
promise_list.push(gadget.state.result_gadget.addItem(result_list[j]));
}
return RSVP.all(promise_list);
});
})
.onEvent("submit", function(event){
this.search(event.target.elements[0].value);
});
(function (window, document, rJS, RSVP) {
var gadget;
rJS(window)
.setState({
model_gadget : null,
parser_gadget : null,
result_gadget : null,
to_load: [
"allemandfacile.rss",
"anglaisfacile.rss",
"duolingo.rss",
"espagnolfacile.rss",
"francaisfacile.rss",
"hgeo_college.rss",
"histoirencours.rss",
"italienfacile.rss",
"lewebpedagogique-lapasserelle.rss",
"mathematiquesfacile.rss",
"physique_chimie_college.rss",
"technologieaucollege27.rss",
"vivelessvt.rss"
]
})
.allowPublicAcquisition("get_model", function(){
return this.getDeclaredGadget("model");
})
.ready(function(){
var model_gadget,
result_gadget;
console.log("ready !");
var gadget = this;
return gadget.getDeclaredGadget("model")
.push(function(model){
model_gadget = model;
})
.push(function(){
return gadget.getDeclaredGadget("result");
})
.push(function(result){
result_gadget = result;
})
.push(function(){
return gadget.getDeclaredGadget("parser");
})
.push(function(result){
return gadget.changeState({
model_gadget : model_gadget,
parser_gadget : result,
result_gadget : result_gadget
});
});
})
.onStateChange(function (modification_dict){
var gadget = this,
promise_list = [],
i;
for (i = 0; i < gadget.state.to_load.length; i++){
promise_list.push(gadget.state.parser_gadget.readFile("../rss-files/" + gadget.state.to_load[i]));
}
RSVP.all(promise_list);
})
.declareMethod("search", function (key){
var gadget = this,
options;
options = {
query:'(title:"% '+key+' %") OR (title: key + "%") OR (body:"% '+key+' %")'
};
return gadget.state.result_gadget.clear()
.push(function(){
return gadget.state.model_gadget.search(options);
})
.push (function(result){
if (result.data.rows.length === 0){
return gadget.state.result_gadget.addItem({
title : "No results found",
link : ""
}, "");
}
var i,
id,
promise_list = [];
for (i = 0; i < result.data.rows.length; i+=1){
id = result.data.rows[i].id;
promise_list.push(gadget.state.model_gadget.get(id));
}
return RSVP.all(promise_list);
})
.push(function(result_list){
var j,
promise_list = [];
for (j = 0; j < result_list.length; j+=1){
promise_list.push(gadget.state.result_gadget.addItem(result_list[j], key));
}
return RSVP.all(promise_list);
});
})
.onEvent("submit", function(event){
this.search(event.target.elements[0].value);
});
}(window, document, rJS, RSVP));
\ No newline at end of file
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