Source: site.view [edit]
Function name: addRecord
Arguments: server,category,id
Description:
Page type: webl
Render function:  
Module: demavu

Page source:

var db = Wub_GetDB("demavu");
var coll = Wub_GetCollection(db, "data");

if server == "-" then
   server = "staging"
end;

var queryObj = Wub_NewDBObject([. "server"=server, "app"="devtools" .]);
var res = Wub_QueryDB(coll, queryObj, 20); // 20 = max results

var selectedGame = "Shark_Showdown";

if Size(res) > 0 then
   selectedGame = res[0].selected;
end;

id = Base64_Decode(id);
var name = id;
id = Wub_ReplaceAll(id, " ", "_");

var path = [];

if category == "games" then
   path = ["-","games", id, "name" ]
else
   path = ["-","games",selectedGame, category, id,"name"]
end;

var obj = [. .];
var ret = "OK";

var done = false;
var i = 0;
every o in path do
   if path[i] != "*" then

      if path[i] == "-" then
         if i == 0 then
            obj["lev" + ToString(i)] := "sXbxqn7udYfN";
         elsif i == 2 then
            obj["lev" + ToString(i)] := selectedGame;
         end
       elsif path[i] == "selected" and i == 1 then
         done = selectedGame
       else
         obj["lev" + ToString(i)] := o;
      end
   end;

   i = i + 1
end;

if done == false then

  obj["value"] := name;
  obj["server"] := server;

  var aDbObj = Wub_NewDBObject(obj);
  Wub_InsertDB(coll, aDbObj);

  ret = ToString(obj);

else
  ret = done
end;

NewPage(ret, "text/plain");