Collaborama About Help Contact Anonymous [login] Source: site.view [edit] Function name: text Arguments: Description: Page type: webl Render function: Module: maybeathome Page source: var res = ""; var res2 = ""; var sessionid = "?"; var listingid = "?"; var sub = "?"; // sessionid,sub,listingid if Size(OPTIONALARGS) > 2 then sessionid = OPTIONALARGS[0] ? "!"; sub = OPTIONALARGS[1] ? "!"; listingid = OPTIONALARGS[2] ? "!"; end; if (sub == "") or (sub == "?") then sub == "*" end; var active = fun (sb) var s = `class="active"`; if (sub != sb) then s = ""; end; s end; var userInfo = WubCall("siteutil.getSessionInfo", ["maybeathome", sessionid]); var username = userInfo.username ? "unknown"; var userRole = userInfo.arg0 ? "buyer"; var sellerId = "unknown"; var sellerType = "seller"; var db = Wub_GetDB("maybeathome"); var coll = Wub_GetCollection(db, "messages"); var listingColl = Wub_GetCollection(db, "listings"); // Query listing for listing record var searchParams = [. "listingId" = listingid .]; var dbobj = Wub_NewDBObject(searchParams); var dbres = Wub_QueryDB(listingColl, dbobj, 30); sellerId = "*"; if Size(dbres) == 1 then sellerId = dbres[0].userId; sellerType = dbres[0].userType; end; var toLabel = Str_ToUpperCase(sellerType) + ": " + sellerId; var toSub = sellerId; if (username == sellerId) then toLabel = "TO EVERYONE"; toSub = "*"; end; // Query messages for listing searchParams = [. "listingId" = listingid .]; dbobj = Wub_NewDBObject(searchParams); dbres = Wub_QueryDB(coll, dbobj, 10000); // <li class="active"><a href="javascript:void(0);">Sanjay<span class="badge">2</span></a></li> // <li><a href="javascript:void(0);">Hugo Daley</a></li> // <li><a href="javascript:void(0);">Adam Cheyer</a></li> res = res + ` <div class="col-md-3 col-sm-4 col-xs-4"> <ul class="list-unstyled contact-list"> <!-- TOSUB: ` + toSub + ` --> <li ` + active(toSub) + ` onclick="selectOwner(this, '` + toSub + `');"><a><span>` + toLabel + `</span></a></li>` + "\n"; var users = {}; if userRole != "buyer" then every r in dbres do if r.to == username then users = users + { r.from } end; end; end; every u in users do res = res + ` <li ` + active(ToString(u)) + `onclick="selectOwner(this, '` + ToString(u) + `');"><a><span>` + ToString(u) + `</span></a></li>` + "\n"; end; res = res + ` </ul> </div> <div class="col-md-9 col-sm-8 col-xs-8"> <div class="chat-scroll-wrapper"> <ul class="media-list chat-media-list">` + "\n"; var count = 0; every r in dbres do var show = (sub == r.to and username == r.from) or (sub == r.from and username == r.to) or (r.to == "*" and userRole == "buyer"); if (show) then count = count + 1; res = res + ` <li class="media">` + "\n"; if r.from == username then res = res + ` <div class="media-left"> <a href="javascript:void(0);">` + r.from + `</a> </div>`; end; res = res + ` <div class="media-body"> <p> ` + r.text + ` </p> </div>` + "\n"; if r.from != username then res = res + ` <div class="media-right"> <a href="javascript:void(0);">` + r.from + `</a> </div>`; end; res = res + ` </li>` + "\n"; end end; if (count == 0) then res = res + "<li><b>No Messages</b></li>\n"; end; res = res + ` </ul> </div> </div>` + "\n"; NewPage(res, "text/html");