Moka-Views.st 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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: 'events'!
  65. pressed
  66. self controller onToggled: self checked not
  67. ! !
  68. !MKCheckboxView methodsFor: 'rendering'!
  69. label
  70. ^ label ifNil: [ '' ]
  71. !
  72. label: aString
  73. label := aString
  74. !
  75. renderContentOn: html
  76. html input
  77. type: 'checkbox';
  78. at: 'checked' put: self checked;
  79. value: self label;
  80. onClick: [ self pressed ]
  81. ! !
  82. MKAspectView subclass: #MKInputView
  83. instanceVariableNames: 'input'
  84. package: 'Moka-Views'!
  85. !MKInputView commentStamp!
  86. I am an input view. My default controller is `MKInputController`.
  87. My controller must answer to `#onEnterPressed:`.!
  88. !MKInputView methodsFor: 'accessing'!
  89. value
  90. ^ input asJQuery val
  91. ! !
  92. !MKInputView methodsFor: 'events'!
  93. enterPressed
  94. self controller onEnterPressed: self value
  95. !
  96. keyDown: anEvent
  97. anEvent which = String cr asciiValue ifTrue: [
  98. self enterPressed ]
  99. ! !
  100. !MKInputView methodsFor: 'rendering'!
  101. renderContentOn: html
  102. input := html input
  103. value: self aspectValue;
  104. onKeyDown: [ :event |
  105. self keyDown: event ];
  106. yourself
  107. ! !