Source: site.view [edit]
Function name: deleteSpeaker
Arguments: name,areYouSure
Description:
Page type: webl
Render function:  
Module: speakaboutai

Page source:

var addPerson = fun(person, create)
   var ok = true;

   // create is false, add to existing index.  "standard" analysis (no stemming). For stemming: "kstem" and "english" (porter)
   var writer = Wub_NewLuceneIndex("speakers", create, "standard"); 
   var doc = Wub_NewLuceneDocument();

  // Add fields to doc

   var default = "AI ";
   var boost = 0;

   every field in ToList(person) do
      var s = (person[field] ? "");
      ok = ok and Wub_AddLuceneField(doc, field, s, true, true, 0); // 0 = no special boost
      default = default + " " + s;
      if field == "boost" then
         boost = (ToInt(person[field]) ? 0)
      end
   end;

   ok = ok and Wub_AddLuceneField(doc, "default", default, true, true, boost); 

   ok = ok and Wub_AddLuceneDocument(writer, doc);
   ok = ok and Wub_OptimizeLucene(writer);
   ok = ok and Wub_CloseLuceneIndex(writer);
end;



if Str_ToLowerCase(areYouSure) == "yes" then

   var fSpeakers = Wub_GetFunctionInfo("speakaboutai.speakerslist");
   var fTags = Wub_GetFunctionInfo("speakaboutai.tagslist");

   var Speakers = WubCall("speakaboutai.speakerslist", []);
   var Tags = WubCall("speakaboutai.tagslist", []);

   var lTags = [];

   var theSpeaker = [. .];
   var rest = [];
   every speaker in Speakers do
      if name == speaker.name then
         theSpeaker = speaker
      else
         rest = rest + [speaker];
         lTags = lTags + Str_Split(speaker.tags, "")
      end;
   end;


   // Re-create lucene index
   addPerson(First(rest), true);

   every speaker in Rest(rest) do
      addPerson(speaker, false);
   end;


   fSpeakers.exec := ToString(rest);
   Wub_SaveFunctionInfo(fSpeakers);

   fTags.exec := ToString(Sort(ToList(ToSet(lTags)), fun(a,b)
      if (Str_ToLowerCase(a) > Str_ToLowerCase(b)) then 1
      elsif (Str_ToLowerCase(a) == Str_ToLowerCase(b)) then 0
      else -1
      end end
   )) + ";";
   Wub_SaveFunctionInfo(fTags);

   var P = NewPage(Markup(WubCall("speakaboutai.searchtools", [])), "text/html");

else

   var res = "<center><b>Delete " + name + ": Are you sure?</b><p>";
   res = res + `<a href='/webl/WubHub_DoIt?cmdline=speakaboutai.deleteSpeaker:"` + name + `",yes'>` + "[YES]</a><br>\n";
   res = res + "<p>If no, hit the back button.</p></center>";
   var P = NewPage(res, "text/html");

end;