// Original script written by Dmitry Kovaliov aka Дмитрий К. with change by Jam aka Хохрев А.

include "common.gs"
include "Signal.gs"
include "gs.gs"

class zmpiket isclass Signal {
 Soup settings;
 StringTable ST;
 string kmnumber1, kmnumber2;

 string MakeProperty(string link, string text) {
  string t;
  if (text=="") {t=ST.GetString("none"); } else {t=text;}
  return HTMLWindow.MakeLink("live://property/"+link,t);
 }

 public string GetDescriptionHTML(void) {
  string ret="<HTML><body>";
  string bgcol=ST.GetString("BGCOLOR");
  string bgcol2=ST.GetString("BGCOLOR2");

  ret=ret+HTMLWindow.StartTable();
  ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(ST.GetString("platetext")));
  ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(ST.GetString("platetext1"),bgcol)+HTMLWindow.MakeCell(MakeProperty("kmnumber1",kmnumber1),bgcol2));
  ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(ST.GetString("platetext2"),bgcol)+HTMLWindow.MakeCell(MakeProperty("kmnumber2",kmnumber2),bgcol2));
  ret=ret+HTMLWindow.EndTable();

  ret=ret+"</Body></html>";
  return ret;
 }

 public string GetPropertyType(string id) {
  string[] tok=Str.Tokens(id,"/");
  if (tok[0]=="kmnumber1") { return "string,0,4"; }
  if (tok[0]=="kmnumber2") { return "string,0,4"; }
  return "link";
 }


 public void SetPropertyValue(string id, string val) {
  string[] tok=Str.Tokens(id,"/");

  if (tok[0]=="kmnumber1") {
   kmnumber1=val;
   if (kmnumber1=="") {SetFXNameText("name0"," ");} else {SetFXNameText("name0",kmnumber1);}
  }
  if (tok[0]=="kmnumber2") {
   kmnumber2=val;
   if (kmnumber2=="") {SetFXNameText("name1"," ");} else {SetFXNameText("name1",kmnumber2);}
  }
 }

 public string GetPropertyName(string id) {
  string[] tok=Str.Tokens(id,"/");
  if (tok[0]=="kmnumber1") { return ST.GetString("platetext1"); }
  if (tok[0]=="kmnumber2") { return ST.GetString("platetext2"); }
  return "";
 }

 public Soup GetProperties(void) {
  Soup db=inherited();
  db.SetNamedTag("kmnumber1",kmnumber1);
  db.SetNamedTag("kmnumber2",kmnumber2);
  return db;
 }

 public void SetProperties(Soup db) {
  kmnumber1=db.GetNamedTag("kmnumber1");
  kmnumber2=db.GetNamedTag("kmnumber2");

  if (kmnumber1=="") {SetFXNameText("name0"," ");} else {SetFXNameText("name0",kmnumber1);}
  if (kmnumber2=="") {SetFXNameText("name1"," ");} else {SetFXNameText("name1",kmnumber2);}

  PostMessage(me,"kdakm","Setup",0);
 }

 public void Init(void) {
  inherited();
  Asset self=GetAsset();
  settings=self.GetConfigSoup().GetNamedSoup("settings-table");
  ST=self.GetStringTable();
   return;
  }

};