BrightSide Workbench Full Report + Source Code
org.turro.www.voteit.VoteItCtrl Class Reference

Public Member Functions

 VoteItCtrl (IConstructor constructor)
 
void setEntityPath (String entityPath)
 
void setForbiden (boolean forbiden)
 
void setAllowed (ContactList allowed)
 
void setAllowedString (String allowedString)
 
void setForbid (boolean forbid)
 
void setForceInternalRender (boolean force)
 
void renderTemplateVotes (boolean container)
 
void renderVotes (boolean container)
 
String getVoteUrl (String id, int i)
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 38 of file www/voteit/VoteItCtrl.java.

Constructor & Destructor Documentation

◆ VoteItCtrl()

org.turro.www.voteit.VoteItCtrl.VoteItCtrl ( IConstructor  constructor)

Definition at line 46 of file www/voteit/VoteItCtrl.java.

46  {
47  this.constructor = constructor;
48  }

Member Function Documentation

◆ getVoteUrl()

String org.turro.www.voteit.VoteItCtrl.getVoteUrl ( String  id,
int  i 
)

Definition at line 182 of file www/voteit/VoteItCtrl.java.

182  {
183  return "$.post(\"" + ElephantContext.getRootWebPath() + "/xpaction/contact\"," +
184  "{ action: \"vote-it\", path: \"" + entityPath + "\"" +
185  (allowedString == null ? "" : ", allowed: \"" + allowedString.replaceAll("'", "-") + "\"") +
186  ", vote: " + i + ", domid: \"" + id + "\" })" +
187  ".done(function(data) { $(\"#" + id + "\").html(data); });";
188  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ renderTemplateVotes()

void org.turro.www.voteit.VoteItCtrl.renderTemplateVotes ( boolean  container)

Definition at line 74 of file www/voteit/VoteItCtrl.java.

74  {
75  IContact contact = Authentication.getIContact();
76  if(!forbiden && forbid) {
77  forbiden = !(allowed != null && allowed.contains(contact));
78  }
79  if(Strings.isBlank(allowedString)) {
80  allowedString = allowed == null ? null : allowed.getCommaSeparatedId();
81  }
82  VoteItInfo vii = VoteItUtil.info(entityPath, allowedString, contact);
83  String id = container ? "vic_" + IdGenerator.generate() : constructor.getParameter("domid");
84  if(contact.isValid()) {
85  ElephantMarker em = new ElephantMarker(constructor);
86  em.put("control", this);
87  em.put("contact", contact);
88  em.put("controlId", id);
89  em.put("container", container);
90  em.put("votes", vii);
91  em.put("forbiden", forbiden);
92  em.put("entityPath", entityPath);
93  em.process("widgets/webcomp", "voteIt");
94  }
95  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ renderVotes()

void org.turro.www.voteit.VoteItCtrl.renderVotes ( boolean  container)

Definition at line 97 of file www/voteit/VoteItCtrl.java.

97  {
98  if(!forceInternalRender && ElephantMarker.existsTemplate(constructor, false, "widgets/webcomp", "voteIt")) {
99  renderTemplateVotes(container);
100  return;
101  }
102  IContact contact = Authentication.getIContact();
103  if(!forbiden && forbid) {
104  forbiden = !(allowed != null && allowed.contains(contact));
105  }
106  if(Strings.isBlank(allowedString)) {
107  allowedString = allowed == null ? null : allowed.getCommaSeparatedId();
108  }
109  VoteItInfo vii = VoteItUtil.info(entityPath, allowedString, contact);
110  html = new HTMLHelper(constructor);
111  long positiveWidth = 0, negativeWidth = 0, nocareWidth = 0;
112  if(vii.getTotalVotes() > 0) {
113  positiveWidth = vii.getPositive() * 60 / vii.getTotalVotes();
114  negativeWidth = vii.getNegative() * 60 / vii.getTotalVotes();
115  nocareWidth = vii.getNocare() * 60 / vii.getTotalVotes();
116  }
117  String id = container ? "vic_" + IdGenerator.generate() : constructor.getParameter("domid");
118  if(container) {
119  html.startTag("div", "id='" + id + "'");
120  }
121  html.startTable("class='voteit-container'")
122  .startTableCol("colspan='3'")
123  .startTag("span", "class='voteit-votes'")
124  .write(vii.getVotes() + "")
125  .endTag()
126  .doTag("br")
127  .startTag("span", "class='voteit-string'")
128  .write(vii.getTotalVotes() + " " + I_.get("Votes"))
129  .endTag()
130  .endTableRow()
131  .startTableCol("colspan='3'")
132  .startTag("div", "style='width:60px' class='voteit-bar'")
133  .startTable("cellpadding='0' cellspacing='0'")
134  .startTableCol("class='voteit-positive' style='" + (positiveWidth == 0 ? "display:none" : "width:" + positiveWidth + "px") + "'")
135  .startTableCol("class='voteit-nocare' style='" + (nocareWidth == 0 ? "display:none" : "width:" + nocareWidth + "px") + "'")
136  .startTableCol("class='voteit-negative' style='" + (negativeWidth == 0 ? "display:none" : "width:" + negativeWidth + "px") + "'")
137  .endTable()
138  .endTableRow();
139  if(contact.isValid()) {
140  if(forbiden) {
141  html.startTableCol("colspan='3'")
142  .doTag("img", new String[] {
143  "src='" + ElephantContext.getRootWebPath() + "/_internal/system/images/locked.png'"
144  })
145  .endTableRow();
146  } else {
147  html.startTableCol("")
148  .startTag("a", "onClick='" + getVoteUrl(id, 1) + "'")
149  .doTag("img", "src='" + ElephantContext.getRootWebPath() + "/_internal/system/images/promote.png'")
150  .endTag()
151  .startTableCol("")
152  .startTag("a", "onClick='" + getVoteUrl(id, 0) + "'")
153  .doTag("img", "src='" + ElephantContext.getRootWebPath() + "/_internal/system/images/nocare.png'")
154  .endTag()
155  .startTableCol("")
156  .startTag("a", "onClick='" + getVoteUrl(id, -1) + "'")
157  .doTag("img", "src='" + ElephantContext.getRootWebPath() + "/_internal/system/images/demote.png'")
158  .endTag()
159  .endTableRow();
160  }
161  String color = "#333";
162  if(vii.getMyVote() != null) {
163  if(vii.getMyVote().getVote() == 1) {
164  color = "#11f605";
165  } else if(vii.getMyVote().getVote() == -1) {
166  color = "#f00900";
167  } else if(vii.getMyVote().getVote() == 0) {
168  color = "#ffa327";
169  }
170  html.startTableCol("colspan='3'")
171  .startTag("span", "class='voteit-string' style='color:" + color + "'")
172  .write(I_.get("My vote"));
173  } else {
174  html.startTableCol("colspan='3'")
175  .startTag("span", "class='voteit-string' style='color:" + color + "'")
176  .write(I_.get("No vote"));
177  }
178  }
179  html.endAllTags();
180  }
HTMLGenerator write(String value)
HTMLGenerator doTag(String tag)
HTMLGenerator startTag(String tag)
HTMLGenerator startTableCol(String attributes)
HTMLGenerator startTable(String attributes)
void renderTemplateVotes(boolean container)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setAllowed()

void org.turro.www.voteit.VoteItCtrl.setAllowed ( ContactList  allowed)

Definition at line 58 of file www/voteit/VoteItCtrl.java.

58  {
59  this.allowed = allowed;
60  }
Here is the caller graph for this function:

◆ setAllowedString()

void org.turro.www.voteit.VoteItCtrl.setAllowedString ( String  allowedString)

Definition at line 62 of file www/voteit/VoteItCtrl.java.

62  {
63  this.allowedString = allowedString;
64  }
Here is the caller graph for this function:

◆ setEntityPath()

void org.turro.www.voteit.VoteItCtrl.setEntityPath ( String  entityPath)

Definition at line 50 of file www/voteit/VoteItCtrl.java.

50  {
51  this.entityPath = entityPath;
52  }
Here is the caller graph for this function:

◆ setForbid()

void org.turro.www.voteit.VoteItCtrl.setForbid ( boolean  forbid)

Definition at line 66 of file www/voteit/VoteItCtrl.java.

66  {
67  this.forbid = forbid;
68  }
Here is the caller graph for this function:

◆ setForbiden()

void org.turro.www.voteit.VoteItCtrl.setForbiden ( boolean  forbiden)

Definition at line 54 of file www/voteit/VoteItCtrl.java.

54  {
55  this.forbiden = forbiden;
56  }
Here is the caller graph for this function:

◆ setForceInternalRender()

void org.turro.www.voteit.VoteItCtrl.setForceInternalRender ( boolean  force)

Definition at line 70 of file www/voteit/VoteItCtrl.java.

70  {
71  forceInternalRender = force;
72  }

The documentation for this class was generated from the following file: