Moka-Views.st 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. Smalltalk current createPackage: 'Moka-Views'!
  2. MKAspectView subclass: #MKButtonView
  3. instanceVariableNames: 'default label'
  4. package: 'Moka-Views'!
  5. !MKButtonView commentStamp!
  6. I am a push button view. My default controller is `MKButtonController`.
  7. My controller must answer to `#onPressed`.
  8. ## API
  9. - Instances can be set a `default` button
  10. - Use `#label:` to set the label string!
  11. !MKButtonView methodsFor: 'accessing'!
  12. cssClass
  13. ^ self isDefault
  14. ifTrue: [ 'default' ]
  15. ifFalse: [ '' ]
  16. !
  17. default
  18. ^ default
  19. !
  20. default: aBoolean
  21. default := aBoolean
  22. !
  23. label
  24. ^ label ifNil: [ self defaultLabel ]
  25. !
  26. label: aString
  27. label := aString
  28. ! !
  29. !MKButtonView methodsFor: 'defaults'!
  30. defaultControllerClass
  31. ^ MKButtonController
  32. !
  33. defaultLabel
  34. ^ 'OK'
  35. ! !
  36. !MKButtonView methodsFor: 'events'!
  37. pressed
  38. self controller onPressed
  39. ! !
  40. !MKButtonView methodsFor: 'rendering'!
  41. renderContentOn: html
  42. html button
  43. class: self cssClass;
  44. with: self label;
  45. onClick: [ self pressed ]
  46. ! !
  47. !MKButtonView methodsFor: 'testing'!
  48. isDefault
  49. ^ self default ifNil: [ false ]
  50. ! !
  51. MKAspectView subclass: #MKCheckboxView
  52. instanceVariableNames: 'label'
  53. package: 'Moka-Views'!
  54. !MKCheckboxView commentStamp!
  55. I am a checkbox view. My default controller is `MKCheckboxController`.
  56. My controller must answer to `#onToggled:`.
  57. ##API
  58. - If no `aspect` is provided, the ckeckbox state will always be off.
  59. - use `#label:` to set the label string.!
  60. !MKCheckboxView methodsFor: 'accessing'!
  61. checked
  62. ^ self aspectValue ifNil: [ false ]
  63. ! !
  64. !MKCheckboxView methodsFor: 'defaults'!
  65. defaultControllerClass
  66. ^ MKCheckboxController
  67. ! !
  68. !MKCheckboxView methodsFor: 'events'!
  69. pressed
  70. self controller onToggled: self checked not
  71. ! !
  72. !MKCheckboxView methodsFor: 'rendering'!
  73. label
  74. ^ label ifNil: [ '' ]
  75. !
  76. label: aString
  77. label := aString
  78. !
  79. renderContentOn: html
  80. | checkbox |
  81. checkbox := html input
  82. type: 'checkbox';
  83. value: self label;
  84. onClick: [ self pressed ].
  85. self checked ifTrue: [
  86. checkbox at: 'checked' put: 'checked' ]
  87. ! !
  88. MKAspectView subclass: #MKInputView
  89. instanceVariableNames: 'input'
  90. package: 'Moka-Views'!
  91. !MKInputView commentStamp!
  92. I am an input view. My default controller is `MKInputController`.
  93. My controller must answer to `#onEnterPressed:`.!
  94. !MKInputView methodsFor: 'accessing'!
  95. value
  96. ^ input asJQuery val
  97. ! !
  98. !MKInputView methodsFor: 'defaults'!
  99. defaultControllerClass
  100. ^ MKInputController
  101. ! !
  102. !MKInputView methodsFor: 'events'!
  103. enterPressed
  104. self controller onEnterPressed: self value
  105. !
  106. keyDown: anEvent
  107. anEvent keyCode = String cr asciiValue ifTrue: [
  108. self enterPressed ]
  109. ! !
  110. !MKInputView methodsFor: 'rendering'!
  111. renderContentOn: html
  112. input := html input
  113. value: self aspectValue;
  114. onKeyDown: [ :event |
  115. self keyDown: event ];
  116. yourself
  117. ! !
  118. MKAspectView subclass: #MKLabelView
  119. instanceVariableNames: 'input'
  120. package: 'Moka-Views'!
  121. !MKLabelView commentStamp!
  122. I am an label view. I display a `String`.!
  123. !MKLabelView methodsFor: 'defaults'!
  124. defaultControllerClass
  125. ^ super defaultControllerClass
  126. ! !
  127. !MKLabelView methodsFor: 'rendering'!
  128. renderContentOn: html
  129. html with: self aspectValue
  130. ! !