Moka-Views.st 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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: ''
  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. renderContentOn: html
  74. | checkbox id |
  75. id := 1000000 atRandom asString.
  76. checkbox := html input
  77. type: 'checkbox';
  78. id: id;
  79. onClick: [ self pressed ].
  80. self checked ifTrue: [
  81. checkbox at: 'checked' put: 'checked' ].
  82. html label
  83. for: id;
  84. with: [ html entity: 'nbsp' ]
  85. ! !
  86. MKAspectView subclass: #MKInputView
  87. instanceVariableNames: 'input'
  88. package: 'Moka-Views'!
  89. !MKInputView commentStamp!
  90. I am an input view. My default controller is `MKInputController`.
  91. My controller must answer to `#onEnterPressed:`.!
  92. !MKInputView methodsFor: 'accessing'!
  93. value
  94. ^ input asJQuery val
  95. ! !
  96. !MKInputView methodsFor: 'defaults'!
  97. defaultControllerClass
  98. ^ MKInputController
  99. ! !
  100. !MKInputView methodsFor: 'events'!
  101. enterPressed
  102. self controller onEnterPressed: self value
  103. !
  104. keyDown: anEvent
  105. anEvent keyCode = String cr asciiValue ifTrue: [
  106. self enterPressed ]
  107. ! !
  108. !MKInputView methodsFor: 'rendering'!
  109. renderContentOn: html
  110. input := html input
  111. value: self aspectValue;
  112. onKeyDown: [ :event |
  113. self keyDown: event ];
  114. yourself
  115. ! !
  116. MKAspectView subclass: #MKLabelView
  117. instanceVariableNames: 'input'
  118. package: 'Moka-Views'!
  119. !MKLabelView commentStamp!
  120. I am an label view. I display a `String`.!
  121. !MKLabelView methodsFor: 'defaults'!
  122. defaultControllerClass
  123. ^ super defaultControllerClass
  124. ! !
  125. !MKLabelView methodsFor: 'rendering'!
  126. renderContentOn: html
  127. html span with: self aspectValue
  128. ! !