2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +00:00

fhemweb_fbcalllist.js: convert Windows to UNIX LF (Forum: #107402)

git-svn-id: https://svn.fhem.de/fhem/trunk@21006 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
markusbloch 2020-01-18 08:16:23 +00:00
parent 2409ea8f9c
commit d3ee78f35d

View File

@ -1,150 +1,150 @@
FW_version["fhemweb_fbcalllist.js"] = "$Id$"; FW_version["fhemweb_fbcalllist.js"] = "$Id$";
// WORKAROUND - should be removed if a more suitable solution is found // WORKAROUND - should be removed if a more suitable solution is found
// remove all similar informid's in all parent elements to ensure further updates. // remove all similar informid's in all parent elements to ensure further updates.
// //
// neccessary if general attribute "group" is set. // neccessary if general attribute "group" is set.
$(function () { $(function () {
$("div[arg=fbcalllist][informid]").each(function (index, obj) { $("div[arg=fbcalllist][informid]").each(function (index, obj) {
name = $(obj).attr("dev"); name = $(obj).attr("dev");
$(obj).parents('[informid="'+name+'"]').removeAttr("informid"); $(obj).parents('[informid="'+name+'"]').removeAttr("informid");
}); });
}); });
function FW_processCallListUpdate(data) function FW_processCallListUpdate(data)
{ {
var table = $(this).find("table.fbcalllist").first(); var table = $(this).find("table.fbcalllist").first();
var json_data = jQuery.parseJSON(data) var json_data = jQuery.parseJSON(data)
// clear the list // clear the list
if(json_data.action == "clear") if(json_data.action == "clear")
{ {
// if the table isn't already empty // if the table isn't already empty
if(!table.find("tr[name=empty]").length) if(!table.find("tr[name=empty]").length)
{ {
table.find("tr[number]").remove(); table.find("tr[number]").remove();
table.append("<tr align=\"center\" name=\"empty\"><td style=\"padding:10px;\" colspan=\""+table.find("tr.header td").length+"\">"+json_data.content+"</td></tr>"); table.append("<tr align=\"center\" name=\"empty\"><td style=\"padding:10px;\" colspan=\""+table.find("tr.header td").length+"\">"+json_data.content+"</td></tr>");
} }
return; return;
} }
// remove deleted item // remove deleted item
if(json_data.action == "delete") if(json_data.action == "delete")
{ {
table.find("tr[index='"+json_data.index+"']").remove(); table.find("tr[index='"+json_data.index+"']").remove();
FW_FbCalllistUpdateRowNumbers(table); FW_FbCalllistUpdateRowNumbers(table);
return; return;
} }
// hide the complete table // hide the complete table
if(json_data.action == "hide") if(json_data.action == "hide")
{ {
table.hide(); table.hide();
return; return;
} }
// show the complete table // show the complete table
if(json_data.action == "show") if(json_data.action == "show")
{ {
table.show(); table.show();
return; return;
} }
// update a item with new data // update a item with new data
if(json_data.action == "update") if(json_data.action == "update")
{ {
if(table.find("tr[index='"+json_data.index+"']").length) if(table.find("tr[index='"+json_data.index+"']").length)
{ {
$.each(json_data.item, function (key, val) { $.each(json_data.item, function (key, val) {
if(key == "line") if(key == "line")
{ return true; } { return true; }
FW_setCallListValue(table,json_data.index,key,val); FW_setCallListValue(table,json_data.index,key,val);
}); });
} }
else // add new tr row with the values) else // add new tr row with the values)
{ {
// delete the empty tr row if it may exist // delete the empty tr row if it may exist
table.find("tr[name=empty]").remove(); table.find("tr[name=empty]").remove();
var new_tr = '<tr align="center" number="'+json_data.item.line+'" index="'+json_data.index+'" class="fbcalllist item '+((json_data.item.line % 2) == 1 ? "odd" : "even")+'">'; var new_tr = '<tr align="center" number="'+json_data.item.line+'" index="'+json_data.index+'" class="fbcalllist item '+((json_data.item.line % 2) == 1 ? "odd" : "even")+'">';
var style = "style=\"padding-left:6px;padding-right:6px;\""; var style = "style=\"padding-left:6px;padding-right:6px;\"";
// create the corresponding <td> tags with the received data // create the corresponding <td> tags with the received data
$.each(json_data.item, function (key, val) { $.each(json_data.item, function (key, val) {
if(key == "line") if(key == "line")
{ return true; } { return true; }
else if(key == "image") else if(key == "image")
{ {
new_tr += '<td name="'+key+'" '+style+'><img style="max-height:3em;" src="'+val+'"></td>'; new_tr += '<td name="'+key+'" '+style+'><img style="max-height:3em;" src="'+val+'"></td>';
} }
else else
{ {
new_tr += '<td name="'+key+'" '+style+'>'+val+'</td>'; new_tr += '<td name="'+key+'" '+style+'>'+val+'</td>';
} }
}); });
new_tr += "</tr>"; new_tr += "</tr>";
// insert new tr into table // insert new tr into table
if(json_data.order == "ascending") if(json_data.order == "ascending")
{ {
table.append(new_tr); table.append(new_tr);
} }
else else
{ {
table.find("tr.header").after(new_tr); table.find("tr.header").after(new_tr);
} }
FW_FbCalllistUpdateRowNumbers(table); FW_FbCalllistUpdateRowNumbers(table);
} }
return; return;
} }
} }
function FW_FbCalllistUpdateRowNumbers(table) function FW_FbCalllistUpdateRowNumbers(table)
{ {
count = 0; count = 0;
table.find("tr.item").each(function(index, obj) { table.find("tr.item").each(function(index, obj) {
var oldClass = ((parseInt($(obj).attr("number")) % 2) == 1 ? "odd" : "even"); var oldClass = ((parseInt($(obj).attr("number")) % 2) == 1 ? "odd" : "even");
$(obj).attr("number", ++count); $(obj).attr("number", ++count);
var newClass = ((count % 2) == 1 ? "odd" : "even"); var newClass = ((count % 2) == 1 ? "odd" : "even");
$(obj).removeClass(oldClass); $(obj).removeClass(oldClass);
$(obj).addClass(newClass); $(obj).addClass(newClass);
$(obj).find("td[name='row']").html(count); $(obj).find("td[name='row']").html(count);
}); });
} }
function FW_setCallListValue(table,index,key,val) function FW_setCallListValue(table,index,key,val)
{ {
var el = table.find("tr[index='"+index+"'] td[name="+key+"]"); var el = table.find("tr[index='"+index+"'] td[name="+key+"]");
if(key == "image") if(key == "image")
{ {
el.children("img").attr("src", val); el.children("img").attr("src", val);
} }
else else
{ {
el.html(val); el.html(val);
} }
} }
function FW_FbCalllistCreate(elName, devName, vArr, currVal, set, params, cmd) function FW_FbCalllistCreate(elName, devName, vArr, currVal, set, params, cmd)
{ {
if(vArr[0] == "fbcalllist") if(vArr[0] == "fbcalllist")
{ {
var newEl = $('div[informid="'+devName+'"]').get(0); var newEl = $('div[informid="'+devName+'"]').get(0);
newEl.setValueFn = FW_processCallListUpdate; newEl.setValueFn = FW_processCallListUpdate;
return newEl; return newEl;
} }
} }
FW_widgets['fbcalllist'] = { FW_widgets['fbcalllist'] = {
createFn:FW_FbCalllistCreate createFn:FW_FbCalllistCreate
}; };