Skip to content

Instantly share code, notes, and snippets.

@lispc
Created April 20, 2014 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lispc/11115255 to your computer and use it in GitHub Desktop.
Save lispc/11115255 to your computer and use it in GitHub Desktop.
The Js bug
var descriptionDisplayLimit = 200;
var ids = [];
var simly = Simly.getInstance();
templateFunc = swig.compile($("#src_item_template").html());
function load_log(){
$.ajax({
url: "/simly/api/get_feedback_log",
dataType: "json",
data: {uname:getLoginInfo().username},
success:function(res){
data = res.data;
for(var i=0;i<data.length;i++){
if(data[i][6]==0)
data[i][6]='B';
else
data[i][6]='C';
}
$("#records").html(swig.compile($("#record_template").html())({"records":data}));
}
});
}
function choose_show(result){
console.log("choose_show called "+result)
$.ajax({
url:"/simly/api/show_feedback",
data:{
uname: getLoginInfo().username,
src_id: ids[0].id,
dst_id1: ids[1].id,
dst_id2: ids[2].id,
result: result
},
success:function(){
console.log("choose_show get data success")
$("#btn"+result).html("<h3>Submit success. Reloading...<h3>");
load_log();
console.log("choose_show calling load_candidate")
load_candidate();
console.log("choose_show calling load_candidate finished")
}
});
console.log("choose_show finished")
}
function load_candidate(){
console.log("enter load_candidate")
$.ajax({
url: "/simly/api/load_feedback_data",
dataType: "json",
success: function(data){
console.log("load_feedback_data success")
function transform(info){
info.full_description = info.description;
if(info.description.length > descriptionDisplayLimit){
info.description_too_long = true;
info.description = info.description.substring(0, descriptionDisplayLimit) + "...";
}
return info;
}
ids = data;
$("#src_id").html(templateFunc({"item":transform(data[0])}));
$("#dst_id1").html(templateFunc({"item":transform(data[1])}));
$("#dst_id2").html(templateFunc({"item":transform(data[2])}));
var btn_template = $("#button_template").html();
var btn_html = swig.compile(btn_template)({});
$("#btn_div").html(btn_html);
$(".btn_view_detail_description").click(function(){
var self = $(this);
var desDom = self.prev(".item_description");
if(desDom.hasClass("detailed")){
self.html("View more");
desDom.removeClass("detailed");
desDom.html(desDom.data("description").substring(0, descriptionDisplayLimit));
}else{
desDom.addClass("detailed");
desDom.html(desDom.data("description"));
self.html("Hide detail");
}
});
$(".button_feedback").click(function(){
$(this).parent().html("<h3>Thanks</h3>");
var index = $(this).data("value");
choose_show(index);
});
console.log("add listener finished")
}
});
}
$(document).ready(function(){
simly.loadHead("#head");
loadSubMenue();
var type = "feed";
$("#sub-menue").find("[data-type='" + type + "']").css("font-weight", "bold").css("padding","5px 0px");
$(document).keydown(function(e){
switch(e.which){
case 37://left
choose_show("0");
return false;
break;
case 38://up
load_candidate();
return false;
break;
case 39://right
choose_show("1");
return false;
break;
default:
return;
}
e.preventDefault();
});
load_log();
load_candidate();
});
var descriptionDisplayLimit = 200;
var ids = [];
var simly = Simly.getInstance();
templateFunc = swig.compile($("#src_item_template").html());
function load_log(){
$.ajax({
url: "/simly/api/get_feedback_log",
dataType: "json",
data: {uname:getLoginInfo().username},
success:function(res){
data = res.data;
for(var i=0;i<data.length;i++){
if(data[i][6]==0)
data[i][6]='B';
else
data[i][6]='C';
}
$("#records").html(swig.compile($("#record_template").html())({"records":data}));
}
});
}
function load_candidate(){
$.ajax({
url: "/simly/api/load_feedback_data",
dataType: "json",
success: function(data){
function transform(info){
info.full_description = info.description;
if(info.description.length > descriptionDisplayLimit){
info.description_too_long = true;
info.description = info.description.substring(0, descriptionDisplayLimit) + "...";
}
return info;
}
ids = data;
$("#src_id").html(templateFunc({"item":transform(data[0])}));
$("#dst_id1").html(templateFunc({"item":transform(data[1])}));
$("#dst_id2").html(templateFunc({"item":transform(data[2])}));
var btn_template = $("#button_template").html();
var btn_html = swig.compile(btn_template)({});
$("#btn_div").html(btn_html);
$(".btn_view_detail_description").click(function(){
var self = $(this);
var desDom = self.prev(".item_description");
if(desDom.hasClass("detailed")){
self.html("View more");
desDom.removeClass("detailed");
desDom.html(desDom.data("description").substring(0, descriptionDisplayLimit));
}else{
desDom.addClass("detailed");
desDom.html(desDom.data("description"));
self.html("Hide detail");
}
});
function choose_show(result){
$.ajax({
url:"/simly/api/show_feedback",
data:{
uname: getLoginInfo().username,
src_id: ids[0].id,
dst_id1: ids[1].id,
dst_id2: ids[2].id,
result: result
},
success:function(){
$("#btn"+result).html("<h3>Submit success. Reloading...<h3>");
load_log();
load_candidate();
}
});
}
$(document).keydown(function(e){
switch(e.which){
case 37://left
choose_show("0");
break;
case 38://up
load_candidate();
break;
case 39://right
choose_show("1");
break;
default:
return;
}
e.preventDefault();
});
$(".button_feedback").click(function(){
$(this).parent().html("<h3>Thanks</h3>");
var index = $(this).data("value");
choose_show(index);
});
}
});
}
$(document).ready(function(){
simly.loadHead("#head");
loadSubMenue();
var type = "feed";
$("#sub-menue").find("[data-type='" + type + "']").css("font-weight", "bold").css("padding","5px 0px");
load_log();
load_candidate();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment