Trapped-Demo.deploy.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. smalltalk.addPackage('Trapped-Demo', {});
  2. smalltalk.addClass('App', smalltalk.ListKeyedIsolatedEntity, [], 'Trapped-Demo');
  3. smalltalk.addMethod(
  4. "_initialize",
  5. smalltalk.method({
  6. selector: "initialize",
  7. fn: function (){
  8. var self=this;
  9. smalltalk.send(self,"_initialize",[],smalltalk.ListKeyedIsolatedEntity);
  10. smalltalk.send(self,"_dispatcher_",[smalltalk.send((smalltalk.SimpleKeyedPubSub || SimpleKeyedPubSub),"_new",[])]);
  11. smalltalk.send(self,"_model_",[smalltalk.send(smalltalk.send((smalltalk.AppModel || AppModel),"_new",[]),"_title_",["Todo"])]);
  12. smalltalk.send((function(){
  13. return smalltalk.send(self,"_modify_do_",[[smalltalk.symbolFor("todos")],(function(){
  14. return [smalltalk.HashedCollection._fromPairs_([smalltalk.send("text","__minus_gt",["learn trapped"]),smalltalk.send("done","__minus_gt",[true])]),smalltalk.HashedCollection._fromPairs_([smalltalk.send("text","__minus_gt",["build a trapped app"]),smalltalk.send("done","__minus_gt",[false])])];
  15. })]);
  16. }),"_valueWithTimeout_",[(2000)]);
  17. return self}
  18. }),
  19. smalltalk.App);
  20. smalltalk.addClass('AppModel', smalltalk.Object, ['title', 'todos', 'todoText'], 'Trapped-Demo');
  21. smalltalk.addMethod(
  22. "_addTodo",
  23. smalltalk.method({
  24. selector: "addTodo",
  25. fn: function (){
  26. var self=this;
  27. smalltalk.send(smalltalk.send(self,"_todos",[]),"_add_",[smalltalk.HashedCollection._fromPairs_([smalltalk.send("text","__minus_gt",[smalltalk.send(self,"_todoText",[])]),smalltalk.send("done","__minus_gt",[false])])]);
  28. smalltalk.send(self,"_todoText_",[""]);
  29. return self}
  30. }),
  31. smalltalk.AppModel);
  32. smalltalk.addMethod(
  33. "_archive",
  34. smalltalk.method({
  35. selector: "archive",
  36. fn: function (){
  37. var self=this;
  38. smalltalk.send(self,"_todos_",[smalltalk.send(self,"_todosNotDone",[])]);
  39. return self}
  40. }),
  41. smalltalk.AppModel);
  42. smalltalk.addMethod(
  43. "_remaining",
  44. smalltalk.method({
  45. selector: "remaining",
  46. fn: function (){
  47. var self=this;
  48. var $1;
  49. $1=smalltalk.send(smalltalk.send(self,"_todosNotDone",[]),"_size",[]);
  50. return $1;
  51. }
  52. }),
  53. smalltalk.AppModel);
  54. smalltalk.addMethod(
  55. "_title",
  56. smalltalk.method({
  57. selector: "title",
  58. fn: function (){
  59. var self=this;
  60. return self["@title"];
  61. }
  62. }),
  63. smalltalk.AppModel);
  64. smalltalk.addMethod(
  65. "_title_",
  66. smalltalk.method({
  67. selector: "title:",
  68. fn: function (aString){
  69. var self=this;
  70. self["@title"]=aString;
  71. return self}
  72. }),
  73. smalltalk.AppModel);
  74. smalltalk.addMethod(
  75. "_todoText",
  76. smalltalk.method({
  77. selector: "todoText",
  78. fn: function (){
  79. var self=this;
  80. return self["@todoText"];
  81. }
  82. }),
  83. smalltalk.AppModel);
  84. smalltalk.addMethod(
  85. "_todoText_",
  86. smalltalk.method({
  87. selector: "todoText:",
  88. fn: function (aString){
  89. var self=this;
  90. self["@todoText"]=aString;
  91. return self}
  92. }),
  93. smalltalk.AppModel);
  94. smalltalk.addMethod(
  95. "_todos",
  96. smalltalk.method({
  97. selector: "todos",
  98. fn: function (){
  99. var self=this;
  100. return self["@todos"];
  101. }
  102. }),
  103. smalltalk.AppModel);
  104. smalltalk.addMethod(
  105. "_todos_",
  106. smalltalk.method({
  107. selector: "todos:",
  108. fn: function (anArray){
  109. var self=this;
  110. self["@todos"]=anArray;
  111. return self}
  112. }),
  113. smalltalk.AppModel);
  114. smalltalk.addMethod(
  115. "_todosNotDone",
  116. smalltalk.method({
  117. selector: "todosNotDone",
  118. fn: function (){
  119. var self=this;
  120. var $1;
  121. $1=smalltalk.send(smalltalk.send(self,"_todos",[]),"_reject_",[(function(each){
  122. return smalltalk.send(each,"_at_",["done"]);
  123. })]);
  124. return $1;
  125. }
  126. }),
  127. smalltalk.AppModel);
  128. smalltalk.addClass('AppView', smalltalk.Widget, [], 'Trapped-Demo');
  129. smalltalk.addMethod(
  130. "_renderOn_",
  131. smalltalk.method({
  132. selector: "renderOn:",
  133. fn: function (html){
  134. var self=this;
  135. var $1,$2,$3,$4,$5,$6,$7,$9,$10,$11,$12,$8;
  136. smalltalk.send([],"_trapDescend_",[(function(snap){
  137. smalltalk.send(smalltalk.send(html,"_h2",[]),"_trap_",[[smalltalk.symbolFor("title")]]);
  138. return smalltalk.send(smalltalk.send(html,"_div",[]),"_trap_toggle_ifNotPresent_",[[smalltalk.symbolFor("todos")],(function(){
  139. return smalltalk.send(snap,"_do_",[(function(){
  140. smalltalk.send(smalltalk.send(html,"_span",[]),"_trap_",[[smalltalk.symbolFor("remaining")]]);
  141. smalltalk.send(html,"_with_",[" of "]);
  142. smalltalk.send(smalltalk.send(html,"_span",[]),"_trap_",[[smalltalk.symbolFor("todos"), smalltalk.symbolFor("size")]]);
  143. smalltalk.send(html,"_with_",[" remaining [ "]);
  144. $1=smalltalk.send(html,"_a",[]);
  145. smalltalk.send($1,"_href_",[""]);
  146. smalltalk.send($1,"_onClick_",[(function(){
  147. return smalltalk.send((function(){
  148. smalltalk.send(snap,"_modify_",[(function(model){
  149. return smalltalk.send(model,"_archive",[]);
  150. })]);
  151. return false;
  152. }),"_value",[]);
  153. })]);
  154. $2=smalltalk.send($1,"_with_",["archive"]);
  155. $2;
  156. smalltalk.send(html,"_with_",[" ]"]);
  157. smalltalk.send(smalltalk.send(html,"_ul",[]),"_trapIter_tag_do_",[[smalltalk.symbolFor("todos")],smalltalk.symbolFor("li"),(function(each){
  158. smalltalk.send(smalltalk.send(html,"_root",[]),"_empty",[]);
  159. $3=smalltalk.send(html,"_input",[]);
  160. smalltalk.send($3,"_type_",["checkbox"]);
  161. $4=smalltalk.send($3,"_trap_",[["done"]]);
  162. $4;
  163. $5=smalltalk.send(html,"_span",[]);
  164. smalltalk.send($5,"_trap_read_",[["done"],(function(model){
  165. return smalltalk.send(smalltalk.send(html,"_root",[]),"_class_",[smalltalk.send("done-","__comma",[model])]);
  166. })]);
  167. $6=smalltalk.send($5,"_trap_",[["text"]]);
  168. return $6;
  169. })]);
  170. $7=smalltalk.send(html,"_form",[]);
  171. smalltalk.send($7,"_onSubmit_",[(function(){
  172. return smalltalk.send((function(){
  173. smalltalk.send(snap,"_modify_",[(function(model){
  174. return smalltalk.send(model,"_addTodo",[]);
  175. })]);
  176. return false;
  177. }),"_value",[]);
  178. })]);
  179. $8=smalltalk.send($7,"_with_",[(function(){
  180. $9=smalltalk.send(html,"_input",[]);
  181. smalltalk.send($9,"_type_",["text"]);
  182. smalltalk.send($9,"_trap_",[[smalltalk.symbolFor("todoText")]]);
  183. smalltalk.send($9,"_at_put_",["size",(30)]);
  184. $10=smalltalk.send($9,"_placeholder_",["add new todo here"]);
  185. $10;
  186. $11=smalltalk.send(html,"_input",[]);
  187. smalltalk.send($11,"_class_",["btn-primary"]);
  188. smalltalk.send($11,"_type_",["submit"]);
  189. $12=smalltalk.send($11,"_value_",["add"]);
  190. return $12;
  191. })]);
  192. return $8;
  193. })]);
  194. }),(function(){
  195. return smalltalk.send(html,"_with_",["Loading ..."]);
  196. })]);
  197. })]);
  198. return self}
  199. }),
  200. smalltalk.AppView);