Moka-Views.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. define("amber_core/Moka-Views", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "amber_core/Moka-Core"], function(smalltalk,nil,_st){
  2. smalltalk.addPackage('Moka-Views');
  3. smalltalk.packages["Moka-Views"].transport = {"type":"amd","amdNamespace":"amber_core"};
  4. smalltalk.addClass('MKButtonView', smalltalk.MKAspectView, ['default', 'label'], 'Moka-Views');
  5. smalltalk.MKButtonView.comment="I am a push button view. My default controller is `MKButtonController`.\x0a\x0aMy controller must answer to `#onPressed`.\x0a\x0a## API\x0a\x0a- Instances can be set a `default` button\x0a- Use `#label:` to set the label string";
  6. smalltalk.addMethod(
  7. smalltalk.method({
  8. selector: "cssClass",
  9. category: 'accessing',
  10. fn: function (){
  11. var self=this;
  12. return smalltalk.withContext(function($ctx1) {
  13. var $2,$1;
  14. $2=self._isDefault();
  15. if(smalltalk.assert($2)){
  16. $1="default";
  17. } else {
  18. $1="";
  19. };
  20. return $1;
  21. }, function($ctx1) {$ctx1.fill(self,"cssClass",{},smalltalk.MKButtonView)})},
  22. args: [],
  23. source: "cssClass\x0a\x09^ self isDefault \x0a\x09\x09ifTrue: [ 'default' ]\x0a\x09\x09ifFalse: [ '' ]",
  24. messageSends: ["ifTrue:ifFalse:", "isDefault"],
  25. referencedClasses: []
  26. }),
  27. smalltalk.MKButtonView);
  28. smalltalk.addMethod(
  29. smalltalk.method({
  30. selector: "default",
  31. category: 'accessing',
  32. fn: function (){
  33. var self=this;
  34. return smalltalk.withContext(function($ctx1) {
  35. var $1;
  36. $1=self["@default"];
  37. return $1;
  38. }, function($ctx1) {$ctx1.fill(self,"default",{},smalltalk.MKButtonView)})},
  39. args: [],
  40. source: "default\x0a\x09^ default",
  41. messageSends: [],
  42. referencedClasses: []
  43. }),
  44. smalltalk.MKButtonView);
  45. smalltalk.addMethod(
  46. smalltalk.method({
  47. selector: "default:",
  48. category: 'accessing',
  49. fn: function (aBoolean){
  50. var self=this;
  51. return smalltalk.withContext(function($ctx1) {
  52. self["@default"]=aBoolean;
  53. return self}, function($ctx1) {$ctx1.fill(self,"default:",{aBoolean:aBoolean},smalltalk.MKButtonView)})},
  54. args: ["aBoolean"],
  55. source: "default: aBoolean\x0a\x09default := aBoolean",
  56. messageSends: [],
  57. referencedClasses: []
  58. }),
  59. smalltalk.MKButtonView);
  60. smalltalk.addMethod(
  61. smalltalk.method({
  62. selector: "defaultControllerClass",
  63. category: 'defaults',
  64. fn: function (){
  65. var self=this;
  66. function $MKButtonController(){return smalltalk.MKButtonController||(typeof MKButtonController=="undefined"?nil:MKButtonController)}
  67. return smalltalk.withContext(function($ctx1) {
  68. var $1;
  69. $1=$MKButtonController();
  70. return $1;
  71. }, function($ctx1) {$ctx1.fill(self,"defaultControllerClass",{},smalltalk.MKButtonView)})},
  72. args: [],
  73. source: "defaultControllerClass\x0a\x09^ MKButtonController",
  74. messageSends: [],
  75. referencedClasses: ["MKButtonController"]
  76. }),
  77. smalltalk.MKButtonView);
  78. smalltalk.addMethod(
  79. smalltalk.method({
  80. selector: "defaultLabel",
  81. category: 'defaults',
  82. fn: function (){
  83. var self=this;
  84. return smalltalk.withContext(function($ctx1) {
  85. return "OK";
  86. }, function($ctx1) {$ctx1.fill(self,"defaultLabel",{},smalltalk.MKButtonView)})},
  87. args: [],
  88. source: "defaultLabel\x0a\x09^ 'OK'",
  89. messageSends: [],
  90. referencedClasses: []
  91. }),
  92. smalltalk.MKButtonView);
  93. smalltalk.addMethod(
  94. smalltalk.method({
  95. selector: "isDefault",
  96. category: 'testing',
  97. fn: function (){
  98. var self=this;
  99. return smalltalk.withContext(function($ctx1) {
  100. var $2,$1;
  101. $2=self._default();
  102. if(($receiver = $2) == nil || $receiver == null){
  103. $1=false;
  104. } else {
  105. $1=$2;
  106. };
  107. return $1;
  108. }, function($ctx1) {$ctx1.fill(self,"isDefault",{},smalltalk.MKButtonView)})},
  109. args: [],
  110. source: "isDefault\x0a\x09^ self default ifNil: [ false ]",
  111. messageSends: ["ifNil:", "default"],
  112. referencedClasses: []
  113. }),
  114. smalltalk.MKButtonView);
  115. smalltalk.addMethod(
  116. smalltalk.method({
  117. selector: "label",
  118. category: 'accessing',
  119. fn: function (){
  120. var self=this;
  121. return smalltalk.withContext(function($ctx1) {
  122. var $2,$1;
  123. $2=self["@label"];
  124. if(($receiver = $2) == nil || $receiver == null){
  125. $1=self._defaultLabel();
  126. } else {
  127. $1=$2;
  128. };
  129. return $1;
  130. }, function($ctx1) {$ctx1.fill(self,"label",{},smalltalk.MKButtonView)})},
  131. args: [],
  132. source: "label\x0a\x09^ label ifNil: [ self defaultLabel ]",
  133. messageSends: ["ifNil:", "defaultLabel"],
  134. referencedClasses: []
  135. }),
  136. smalltalk.MKButtonView);
  137. smalltalk.addMethod(
  138. smalltalk.method({
  139. selector: "label:",
  140. category: 'accessing',
  141. fn: function (aString){
  142. var self=this;
  143. return smalltalk.withContext(function($ctx1) {
  144. self["@label"]=aString;
  145. return self}, function($ctx1) {$ctx1.fill(self,"label:",{aString:aString},smalltalk.MKButtonView)})},
  146. args: ["aString"],
  147. source: "label: aString\x0a\x09label := aString",
  148. messageSends: [],
  149. referencedClasses: []
  150. }),
  151. smalltalk.MKButtonView);
  152. smalltalk.addMethod(
  153. smalltalk.method({
  154. selector: "pressed",
  155. category: 'events',
  156. fn: function (){
  157. var self=this;
  158. return smalltalk.withContext(function($ctx1) {
  159. _st(self._controller())._onPressed();
  160. return self}, function($ctx1) {$ctx1.fill(self,"pressed",{},smalltalk.MKButtonView)})},
  161. args: [],
  162. source: "pressed\x0a\x09self controller onPressed",
  163. messageSends: ["onPressed", "controller"],
  164. referencedClasses: []
  165. }),
  166. smalltalk.MKButtonView);
  167. smalltalk.addMethod(
  168. smalltalk.method({
  169. selector: "renderContentOn:",
  170. category: 'rendering',
  171. fn: function (html){
  172. var self=this;
  173. return smalltalk.withContext(function($ctx1) {
  174. var $1,$2;
  175. $1=_st(html)._button();
  176. _st($1)._class_(self._cssClass());
  177. _st($1)._with_(self._label());
  178. $2=_st($1)._onClick_((function(){
  179. return smalltalk.withContext(function($ctx2) {
  180. return self._pressed();
  181. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  182. return self}, function($ctx1) {$ctx1.fill(self,"renderContentOn:",{html:html},smalltalk.MKButtonView)})},
  183. args: ["html"],
  184. source: "renderContentOn: html\x0a\x09html button\x0a\x09\x09class: self cssClass;\x0a\x09\x09with: self label;\x0a\x09\x09onClick: [ self pressed ]",
  185. messageSends: ["class:", "button", "cssClass", "with:", "label", "onClick:", "pressed"],
  186. referencedClasses: []
  187. }),
  188. smalltalk.MKButtonView);
  189. smalltalk.addClass('MKCheckboxView', smalltalk.MKAspectView, [], 'Moka-Views');
  190. smalltalk.MKCheckboxView.comment="I am a checkbox view. My default controller is `MKCheckboxController`.\x0a\x0aMy controller must answer to `#onToggled:`.\x0a\x0a##API\x0a\x0a- If no `aspect` is provided, the ckeckbox state will always be off.\x0a- use `#label:` to set the label string.";
  191. smalltalk.addMethod(
  192. smalltalk.method({
  193. selector: "checked",
  194. category: 'accessing',
  195. fn: function (){
  196. var self=this;
  197. return smalltalk.withContext(function($ctx1) {
  198. var $2,$1;
  199. $2=self._aspectValue();
  200. if(($receiver = $2) == nil || $receiver == null){
  201. $1=false;
  202. } else {
  203. $1=$2;
  204. };
  205. return $1;
  206. }, function($ctx1) {$ctx1.fill(self,"checked",{},smalltalk.MKCheckboxView)})},
  207. args: [],
  208. source: "checked\x0a\x09^ self aspectValue ifNil: [ false ]",
  209. messageSends: ["ifNil:", "aspectValue"],
  210. referencedClasses: []
  211. }),
  212. smalltalk.MKCheckboxView);
  213. smalltalk.addMethod(
  214. smalltalk.method({
  215. selector: "defaultControllerClass",
  216. category: 'defaults',
  217. fn: function (){
  218. var self=this;
  219. function $MKCheckboxController(){return smalltalk.MKCheckboxController||(typeof MKCheckboxController=="undefined"?nil:MKCheckboxController)}
  220. return smalltalk.withContext(function($ctx1) {
  221. return $MKCheckboxController();
  222. }, function($ctx1) {$ctx1.fill(self,"defaultControllerClass",{},smalltalk.MKCheckboxView)})},
  223. args: [],
  224. source: "defaultControllerClass\x0a\x09^ MKCheckboxController",
  225. messageSends: [],
  226. referencedClasses: ["MKCheckboxController"]
  227. }),
  228. smalltalk.MKCheckboxView);
  229. smalltalk.addMethod(
  230. smalltalk.method({
  231. selector: "pressed",
  232. category: 'events',
  233. fn: function (){
  234. var self=this;
  235. return smalltalk.withContext(function($ctx1) {
  236. _st(self._controller())._onToggled_(_st(self._checked())._not());
  237. return self}, function($ctx1) {$ctx1.fill(self,"pressed",{},smalltalk.MKCheckboxView)})},
  238. args: [],
  239. source: "pressed\x0a\x09self controller onToggled: self checked not",
  240. messageSends: ["onToggled:", "controller", "not", "checked"],
  241. referencedClasses: []
  242. }),
  243. smalltalk.MKCheckboxView);
  244. smalltalk.addMethod(
  245. smalltalk.method({
  246. selector: "renderContentOn:",
  247. category: 'rendering',
  248. fn: function (html){
  249. var self=this;
  250. var checkbox,id;
  251. return smalltalk.withContext(function($ctx1) {
  252. var $1,$2,$3,$4,$5;
  253. id=_st((1000000)._atRandom())._asString();
  254. $1=_st(html)._input();
  255. _st($1)._type_("checkbox");
  256. _st($1)._id_(id);
  257. $2=_st($1)._onClick_((function(){
  258. return smalltalk.withContext(function($ctx2) {
  259. return self._pressed();
  260. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  261. checkbox=$2;
  262. $3=self._checked();
  263. if(smalltalk.assert($3)){
  264. _st(checkbox)._at_put_("checked","checked");
  265. };
  266. $4=_st(html)._label();
  267. _st($4)._for_(id);
  268. $5=_st($4)._with_((function(){
  269. return smalltalk.withContext(function($ctx2) {
  270. return _st(html)._entity_("nbsp");
  271. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,3)})}));
  272. return self}, function($ctx1) {$ctx1.fill(self,"renderContentOn:",{html:html,checkbox:checkbox,id:id},smalltalk.MKCheckboxView)})},
  273. args: ["html"],
  274. source: "renderContentOn: html\x0a\x09| checkbox id |\x0a\x09\x0a\x09 id := 1000000 atRandom asString.\x0a\x09\x0a\x09checkbox := html input\x0a\x09\x09type: 'checkbox';\x0a\x09\x09id: id;\x0a\x09\x09onClick: [ self pressed ].\x0a\x09\x09\x0a\x09self checked ifTrue: [ \x0a\x09\x09checkbox at: 'checked' put: 'checked' ].\x0a\x09\x09\x0a\x09html label\x0a\x09\x09for: id;\x0a\x09\x09with: [ html entity: 'nbsp' ]",
  275. messageSends: ["asString", "atRandom", "type:", "input", "id:", "onClick:", "pressed", "ifTrue:", "checked", "at:put:", "for:", "label", "with:", "entity:"],
  276. referencedClasses: []
  277. }),
  278. smalltalk.MKCheckboxView);
  279. smalltalk.addClass('MKInputView', smalltalk.MKAspectView, ['input'], 'Moka-Views');
  280. smalltalk.MKInputView.comment="I am an input view. My default controller is `MKInputController`.\x0a\x0aMy controller must answer to `#onEnterPressed:`.";
  281. smalltalk.addMethod(
  282. smalltalk.method({
  283. selector: "defaultControllerClass",
  284. category: 'defaults',
  285. fn: function (){
  286. var self=this;
  287. function $MKInputController(){return smalltalk.MKInputController||(typeof MKInputController=="undefined"?nil:MKInputController)}
  288. return smalltalk.withContext(function($ctx1) {
  289. return $MKInputController();
  290. }, function($ctx1) {$ctx1.fill(self,"defaultControllerClass",{},smalltalk.MKInputView)})},
  291. args: [],
  292. source: "defaultControllerClass\x0a\x09^ MKInputController",
  293. messageSends: [],
  294. referencedClasses: ["MKInputController"]
  295. }),
  296. smalltalk.MKInputView);
  297. smalltalk.addMethod(
  298. smalltalk.method({
  299. selector: "enterPressed",
  300. category: 'events',
  301. fn: function (){
  302. var self=this;
  303. return smalltalk.withContext(function($ctx1) {
  304. _st(self._controller())._onEnterPressed_(self._value());
  305. return self}, function($ctx1) {$ctx1.fill(self,"enterPressed",{},smalltalk.MKInputView)})},
  306. args: [],
  307. source: "enterPressed\x0a\x09self controller onEnterPressed: self value",
  308. messageSends: ["onEnterPressed:", "controller", "value"],
  309. referencedClasses: []
  310. }),
  311. smalltalk.MKInputView);
  312. smalltalk.addMethod(
  313. smalltalk.method({
  314. selector: "keyDown:",
  315. category: 'events',
  316. fn: function (anEvent){
  317. var self=this;
  318. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  319. return smalltalk.withContext(function($ctx1) {
  320. var $1;
  321. $1=_st(_st(anEvent)._keyCode()).__eq(_st(_st($String())._cr())._asciiValue());
  322. if(smalltalk.assert($1)){
  323. self._enterPressed();
  324. };
  325. return self}, function($ctx1) {$ctx1.fill(self,"keyDown:",{anEvent:anEvent},smalltalk.MKInputView)})},
  326. args: ["anEvent"],
  327. source: "keyDown: anEvent\x0a\x09anEvent keyCode = String cr asciiValue ifTrue: [\x0a\x09\x09self enterPressed ]",
  328. messageSends: ["ifTrue:", "=", "keyCode", "asciiValue", "cr", "enterPressed"],
  329. referencedClasses: ["String"]
  330. }),
  331. smalltalk.MKInputView);
  332. smalltalk.addMethod(
  333. smalltalk.method({
  334. selector: "renderContentOn:",
  335. category: 'rendering',
  336. fn: function (html){
  337. var self=this;
  338. return smalltalk.withContext(function($ctx1) {
  339. var $1,$2;
  340. $1=_st(html)._input();
  341. _st($1)._value_(self._aspectValue());
  342. _st($1)._onKeyDown_((function(event){
  343. return smalltalk.withContext(function($ctx2) {
  344. return self._keyDown_(event);
  345. }, function($ctx2) {$ctx2.fillBlock({event:event},$ctx1,1)})}));
  346. $2=_st($1)._yourself();
  347. self["@input"]=$2;
  348. return self}, function($ctx1) {$ctx1.fill(self,"renderContentOn:",{html:html},smalltalk.MKInputView)})},
  349. args: ["html"],
  350. source: "renderContentOn: html\x0a\x09input := html input\x0a\x09\x09value: self aspectValue;\x0a\x09\x09onKeyDown: [ :event |\x0a\x09\x09\x09self keyDown: event ];\x0a\x09\x09yourself",
  351. messageSends: ["value:", "input", "aspectValue", "onKeyDown:", "keyDown:", "yourself"],
  352. referencedClasses: []
  353. }),
  354. smalltalk.MKInputView);
  355. smalltalk.addMethod(
  356. smalltalk.method({
  357. selector: "value",
  358. category: 'accessing',
  359. fn: function (){
  360. var self=this;
  361. return smalltalk.withContext(function($ctx1) {
  362. var $1;
  363. $1=_st(_st(self["@input"])._asJQuery())._val();
  364. return $1;
  365. }, function($ctx1) {$ctx1.fill(self,"value",{},smalltalk.MKInputView)})},
  366. args: [],
  367. source: "value\x0a\x09^ input asJQuery val",
  368. messageSends: ["val", "asJQuery"],
  369. referencedClasses: []
  370. }),
  371. smalltalk.MKInputView);
  372. smalltalk.addClass('MKLabelView', smalltalk.MKAspectView, ['input'], 'Moka-Views');
  373. smalltalk.MKLabelView.comment="I am an label view. I display a `String`.";
  374. smalltalk.addMethod(
  375. smalltalk.method({
  376. selector: "defaultControllerClass",
  377. category: 'defaults',
  378. fn: function (){
  379. var self=this;
  380. return smalltalk.withContext(function($ctx1) {
  381. var $1;
  382. $1=smalltalk.MKLabelView.superclass.fn.prototype._defaultControllerClass.apply(_st(self), []);
  383. return $1;
  384. }, function($ctx1) {$ctx1.fill(self,"defaultControllerClass",{},smalltalk.MKLabelView)})},
  385. args: [],
  386. source: "defaultControllerClass\x0a\x09^ super defaultControllerClass",
  387. messageSends: ["defaultControllerClass"],
  388. referencedClasses: []
  389. }),
  390. smalltalk.MKLabelView);
  391. smalltalk.addMethod(
  392. smalltalk.method({
  393. selector: "renderContentOn:",
  394. category: 'rendering',
  395. fn: function (html){
  396. var self=this;
  397. return smalltalk.withContext(function($ctx1) {
  398. _st(_st(html)._span())._with_(self._aspectValue());
  399. return self}, function($ctx1) {$ctx1.fill(self,"renderContentOn:",{html:html},smalltalk.MKLabelView)})},
  400. args: ["html"],
  401. source: "renderContentOn: html\x0a\x09html span with: self aspectValue",
  402. messageSends: ["with:", "span", "aspectValue"],
  403. referencedClasses: []
  404. }),
  405. smalltalk.MKLabelView);
  406. });