Moka-Core.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. define("amber_core/Moka-Core", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "amber_core/Kernel-Objects", "amber_core/Canvas"], function(smalltalk,nil,_st){
  2. smalltalk.addPackage('Moka-Core');
  3. smalltalk.packages["Moka-Core"].transport = {"type":"amd","amdNamespace":"amber_core"};
  4. smalltalk.addClass('MKController', smalltalk.Object, ['view', 'model'], 'Moka-Core');
  5. smalltalk.MKController.comment="I implement the Controller part of the MVC pattern in Moka.\x0a\x0aI hold onto my `model` and `view`, set with `MKView >> controller:`.";
  6. smalltalk.addMethod(
  7. smalltalk.method({
  8. selector: "model",
  9. category: 'accessing',
  10. fn: function (){
  11. var self=this;
  12. return smalltalk.withContext(function($ctx1) {
  13. var $1;
  14. $1=self["@model"];
  15. return $1;
  16. }, function($ctx1) {$ctx1.fill(self,"model",{},smalltalk.MKController)})},
  17. args: [],
  18. source: "model\x0a\x09^ model",
  19. messageSends: [],
  20. referencedClasses: []
  21. }),
  22. smalltalk.MKController);
  23. smalltalk.addMethod(
  24. smalltalk.method({
  25. selector: "model:",
  26. category: 'accessing',
  27. fn: function (aModel){
  28. var self=this;
  29. return smalltalk.withContext(function($ctx1) {
  30. self["@model"]=aModel;
  31. return self}, function($ctx1) {$ctx1.fill(self,"model:",{aModel:aModel},smalltalk.MKController)})},
  32. args: ["aModel"],
  33. source: "model: aModel\x0a\x09model := aModel",
  34. messageSends: [],
  35. referencedClasses: []
  36. }),
  37. smalltalk.MKController);
  38. smalltalk.addMethod(
  39. smalltalk.method({
  40. selector: "view",
  41. category: 'accessing',
  42. fn: function (){
  43. var self=this;
  44. return smalltalk.withContext(function($ctx1) {
  45. var $1;
  46. $1=self["@view"];
  47. return $1;
  48. }, function($ctx1) {$ctx1.fill(self,"view",{},smalltalk.MKController)})},
  49. args: [],
  50. source: "view\x0a\x09^ view",
  51. messageSends: [],
  52. referencedClasses: []
  53. }),
  54. smalltalk.MKController);
  55. smalltalk.addMethod(
  56. smalltalk.method({
  57. selector: "view:",
  58. category: 'accessing',
  59. fn: function (aView){
  60. var self=this;
  61. return smalltalk.withContext(function($ctx1) {
  62. self["@view"]=aView;
  63. return self}, function($ctx1) {$ctx1.fill(self,"view:",{aView:aView},smalltalk.MKController)})},
  64. args: ["aView"],
  65. source: "view: aView\x0a\x09view := aView",
  66. messageSends: [],
  67. referencedClasses: []
  68. }),
  69. smalltalk.MKController);
  70. smalltalk.addClass('MKAspectController', smalltalk.MKController, ['aspect'], 'Moka-Core');
  71. smalltalk.MKAspectController.comment="I am an abstract controller for performing one action using an `aspect` on a model.\x0a\x0a## API\x0a\x0a- Use `#aspect:` to plug a selector to be performed on the model\x0a- Subclasses can either use `#performActionWith:` or `#performAction` to evaluate the `aspect` selector on the model with one or no argument.";
  72. smalltalk.addMethod(
  73. smalltalk.method({
  74. selector: "aspect",
  75. category: 'accessing',
  76. fn: function (){
  77. var self=this;
  78. return smalltalk.withContext(function($ctx1) {
  79. var $1;
  80. $1=self["@aspect"];
  81. return $1;
  82. }, function($ctx1) {$ctx1.fill(self,"aspect",{},smalltalk.MKAspectController)})},
  83. args: [],
  84. source: "aspect\x0a\x09^ aspect",
  85. messageSends: [],
  86. referencedClasses: []
  87. }),
  88. smalltalk.MKAspectController);
  89. smalltalk.addMethod(
  90. smalltalk.method({
  91. selector: "aspect:",
  92. category: 'accessing',
  93. fn: function (aSelector){
  94. var self=this;
  95. return smalltalk.withContext(function($ctx1) {
  96. self["@aspect"]=aSelector;
  97. return self}, function($ctx1) {$ctx1.fill(self,"aspect:",{aSelector:aSelector},smalltalk.MKAspectController)})},
  98. args: ["aSelector"],
  99. source: "aspect: aSelector\x0a\x09aspect := aSelector",
  100. messageSends: [],
  101. referencedClasses: []
  102. }),
  103. smalltalk.MKAspectController);
  104. smalltalk.addMethod(
  105. smalltalk.method({
  106. selector: "performAction",
  107. category: 'actions',
  108. fn: function (){
  109. var self=this;
  110. return smalltalk.withContext(function($ctx1) {
  111. var $1,$2,$3;
  112. $1=self._aspect();
  113. $ctx1.sendIdx["aspect"]=1;
  114. if(($receiver = $1) == nil || $receiver == null){
  115. $1;
  116. } else {
  117. $2=self._model();
  118. $3=self._aspect();
  119. _st($2)._perform_($3);
  120. };
  121. return self}, function($ctx1) {$ctx1.fill(self,"performAction",{},smalltalk.MKAspectController)})},
  122. args: [],
  123. source: "performAction\x0a\x09self aspect ifNotNil: [\x0a\x09\x09self model \x0a\x09\x09\x09perform: self aspect ]",
  124. messageSends: ["ifNotNil:", "aspect", "perform:", "model"],
  125. referencedClasses: []
  126. }),
  127. smalltalk.MKAspectController);
  128. smalltalk.addMethod(
  129. smalltalk.method({
  130. selector: "performActionWith:",
  131. category: 'actions',
  132. fn: function (anObject){
  133. var self=this;
  134. return smalltalk.withContext(function($ctx1) {
  135. var $1;
  136. $1=self._aspect();
  137. $ctx1.sendIdx["aspect"]=1;
  138. if(($receiver = $1) == nil || $receiver == null){
  139. return self;
  140. } else {
  141. $1;
  142. };
  143. _st(self._model())._perform_withArguments_(_st(self._aspect())._asMutator(),[anObject]);
  144. return self}, function($ctx1) {$ctx1.fill(self,"performActionWith:",{anObject:anObject},smalltalk.MKAspectController)})},
  145. args: ["anObject"],
  146. source: "performActionWith: anObject\x0a\x09self aspect ifNil: [ ^ self ].\x0a\x09\x0a\x09self model \x0a\x09\x09perform: self aspect asMutator\x0a\x09\x09withArguments: { anObject }",
  147. messageSends: ["ifNil:", "aspect", "perform:withArguments:", "model", "asMutator"],
  148. referencedClasses: []
  149. }),
  150. smalltalk.MKAspectController);
  151. smalltalk.addClass('MKModel', smalltalk.Object, ['announcer'], 'Moka-Core');
  152. smalltalk.MKModel.comment="I implement the Model part of the MVC pattern in Moka.\x0a\x0aI am the abstract superclass of all Moka model. The observer pattern is implemented through an `announcer` object.\x0a\x0a## API\x0a\x0a- Listening\x0a\x0a Use `#on:do:` or `#on:send:to:` to listen to model changes\x0a\x0a- Triggering\x0a\x0a `#changed:` is the builtin method used to trigger `#update:` in views.\x0a Use `#announce:` in subclasses to trigger announcements to listeners.";
  153. smalltalk.addMethod(
  154. smalltalk.method({
  155. selector: "announce:",
  156. category: 'announcements',
  157. fn: function (anAnnouncement){
  158. var self=this;
  159. return smalltalk.withContext(function($ctx1) {
  160. _st(self["@announcer"])._announce_(anAnnouncement);
  161. return self}, function($ctx1) {$ctx1.fill(self,"announce:",{anAnnouncement:anAnnouncement},smalltalk.MKModel)})},
  162. args: ["anAnnouncement"],
  163. source: "announce: anAnnouncement\x0a\x09announcer announce: anAnnouncement",
  164. messageSends: ["announce:"],
  165. referencedClasses: []
  166. }),
  167. smalltalk.MKModel);
  168. smalltalk.addMethod(
  169. smalltalk.method({
  170. selector: "changed:",
  171. category: 'announcements',
  172. fn: function (aSelector){
  173. var self=this;
  174. function $MKModelChanged(){return smalltalk.MKModelChanged||(typeof MKModelChanged=="undefined"?nil:MKModelChanged)}
  175. return smalltalk.withContext(function($ctx1) {
  176. self._announce_(_st($MKModelChanged())._aspect_(aSelector));
  177. return self}, function($ctx1) {$ctx1.fill(self,"changed:",{aSelector:aSelector},smalltalk.MKModel)})},
  178. args: ["aSelector"],
  179. source: "changed: aSelector\x0a\x09\x22Trigger `#update:` to all listening aspect views\x22\x0a\x09\x0a\x09self announce: (MKModelChanged aspect: aSelector)",
  180. messageSends: ["announce:", "aspect:"],
  181. referencedClasses: ["MKModelChanged"]
  182. }),
  183. smalltalk.MKModel);
  184. smalltalk.addMethod(
  185. smalltalk.method({
  186. selector: "initialize",
  187. category: 'initialization',
  188. fn: function (){
  189. var self=this;
  190. function $Announcer(){return smalltalk.Announcer||(typeof Announcer=="undefined"?nil:Announcer)}
  191. return smalltalk.withContext(function($ctx1) {
  192. smalltalk.MKModel.superclass.fn.prototype._initialize.apply(_st(self), []);
  193. self["@announcer"]=_st($Announcer())._new();
  194. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.MKModel)})},
  195. args: [],
  196. source: "initialize\x0a\x09super initialize.\x0a\x09announcer := Announcer new",
  197. messageSends: ["initialize", "new"],
  198. referencedClasses: ["Announcer"]
  199. }),
  200. smalltalk.MKModel);
  201. smalltalk.addMethod(
  202. smalltalk.method({
  203. selector: "on:do:",
  204. category: 'announcements',
  205. fn: function (anAnnouncement,aBlock){
  206. var self=this;
  207. return smalltalk.withContext(function($ctx1) {
  208. _st(self["@announcer"])._on_do_(anAnnouncement,aBlock);
  209. return self}, function($ctx1) {$ctx1.fill(self,"on:do:",{anAnnouncement:anAnnouncement,aBlock:aBlock},smalltalk.MKModel)})},
  210. args: ["anAnnouncement", "aBlock"],
  211. source: "on: anAnnouncement do: aBlock\x0a\x09announcer on: anAnnouncement do: aBlock",
  212. messageSends: ["on:do:"],
  213. referencedClasses: []
  214. }),
  215. smalltalk.MKModel);
  216. smalltalk.addMethod(
  217. smalltalk.method({
  218. selector: "on:send:to:",
  219. category: 'announcements',
  220. fn: function (anAnnouncement,aSelector,anObject){
  221. var self=this;
  222. return smalltalk.withContext(function($ctx1) {
  223. _st(self["@announcer"])._on_send_to_(anAnnouncement,aSelector,anObject);
  224. return self}, function($ctx1) {$ctx1.fill(self,"on:send:to:",{anAnnouncement:anAnnouncement,aSelector:aSelector,anObject:anObject},smalltalk.MKModel)})},
  225. args: ["anAnnouncement", "aSelector", "anObject"],
  226. source: "on: anAnnouncement send: aSelector to: anObject\x0a\x09announcer on: anAnnouncement send: aSelector to: anObject",
  227. messageSends: ["on:send:to:"],
  228. referencedClasses: []
  229. }),
  230. smalltalk.MKModel);
  231. smalltalk.addClass('MKModelChanged', smalltalk.Object, ['aspect'], 'Moka-Core');
  232. smalltalk.MKModelChanged.comment="I am an announcement announced when a model is changed.";
  233. smalltalk.addMethod(
  234. smalltalk.method({
  235. selector: "aspect",
  236. category: 'accessing',
  237. fn: function (){
  238. var self=this;
  239. return smalltalk.withContext(function($ctx1) {
  240. var $1;
  241. $1=self["@aspect"];
  242. return $1;
  243. }, function($ctx1) {$ctx1.fill(self,"aspect",{},smalltalk.MKModelChanged)})},
  244. args: [],
  245. source: "aspect\x0a\x09^ aspect",
  246. messageSends: [],
  247. referencedClasses: []
  248. }),
  249. smalltalk.MKModelChanged);
  250. smalltalk.addMethod(
  251. smalltalk.method({
  252. selector: "aspect:",
  253. category: 'accessing',
  254. fn: function (aSelector){
  255. var self=this;
  256. return smalltalk.withContext(function($ctx1) {
  257. self["@aspect"]=aSelector;
  258. return self}, function($ctx1) {$ctx1.fill(self,"aspect:",{aSelector:aSelector},smalltalk.MKModelChanged)})},
  259. args: ["aSelector"],
  260. source: "aspect: aSelector\x0a\x09aspect := aSelector",
  261. messageSends: [],
  262. referencedClasses: []
  263. }),
  264. smalltalk.MKModelChanged);
  265. smalltalk.addMethod(
  266. smalltalk.method({
  267. selector: "aspect:",
  268. category: 'instance creation',
  269. fn: function (aSelector){
  270. var self=this;
  271. return smalltalk.withContext(function($ctx1) {
  272. var $2,$3,$1;
  273. $2=self._new();
  274. _st($2)._aspect_(aSelector);
  275. $3=_st($2)._yourself();
  276. $1=$3;
  277. return $1;
  278. }, function($ctx1) {$ctx1.fill(self,"aspect:",{aSelector:aSelector},smalltalk.MKModelChanged.klass)})},
  279. args: ["aSelector"],
  280. source: "aspect: aSelector\x0a\x09^ self new\x0a\x09\x09aspect: aSelector;\x0a\x09\x09yourself",
  281. messageSends: ["aspect:", "new", "yourself"],
  282. referencedClasses: []
  283. }),
  284. smalltalk.MKModelChanged.klass);
  285. smalltalk.addClass('MKView', smalltalk.Widget, ['controller', 'model', 'wrapper'], 'Moka-Core');
  286. smalltalk.MKView.comment="I implement the View part of the MVC pattern in Moka.\x0a\x0a## API\x0a- Instance can be created with the `MKView class >> model:*` convenience methods\x0a- rendering is done through `#renderContentOn:`, to be overridden in concrete view classes\x0a- `#update` provide updating facility, refreshing the entire view\x0a- subclasses can override `#defaultControllerClass` to provide a default controller specific to a view\x0a- subclasses can override `#observeModel`.";
  287. smalltalk.addMethod(
  288. smalltalk.method({
  289. selector: "controller",
  290. category: 'accessing',
  291. fn: function (){
  292. var self=this;
  293. return smalltalk.withContext(function($ctx1) {
  294. var $1,$2;
  295. $1=self["@controller"];
  296. if(($receiver = $1) == nil || $receiver == null){
  297. self._controller_(self._defaultController());
  298. } else {
  299. $1;
  300. };
  301. $2=self["@controller"];
  302. return $2;
  303. }, function($ctx1) {$ctx1.fill(self,"controller",{},smalltalk.MKView)})},
  304. args: [],
  305. source: "controller\x0a\x09\x22Answer the current receiver's controller.\x0a\x09If no controller is installed yet, install the `defaultController`\x0a\x09of the receiver and answer it.\x22\x0a\x09\x0a\x09controller ifNil: [ \x0a\x09\x09self controller: self defaultController ].\x0a\x09^ controller",
  306. messageSends: ["ifNil:", "controller:", "defaultController"],
  307. referencedClasses: []
  308. }),
  309. smalltalk.MKView);
  310. smalltalk.addMethod(
  311. smalltalk.method({
  312. selector: "controller:",
  313. category: 'accessing',
  314. fn: function (aController){
  315. var self=this;
  316. return smalltalk.withContext(function($ctx1) {
  317. var $1,$2;
  318. self["@controller"]=aController;
  319. $1=aController;
  320. _st($1)._view_(self);
  321. $2=_st($1)._model_(self._model());
  322. return self}, function($ctx1) {$ctx1.fill(self,"controller:",{aController:aController},smalltalk.MKView)})},
  323. args: ["aController"],
  324. source: "controller: aController\x0a\x09\x22Install `aController` to be the receiver's controller\x22\x0a\x09\x0a\x09controller := aController.\x0a\x09aController \x0a\x09\x09view: self;\x0a\x09\x09model: self model",
  325. messageSends: ["view:", "model:", "model"],
  326. referencedClasses: []
  327. }),
  328. smalltalk.MKView);
  329. smalltalk.addMethod(
  330. smalltalk.method({
  331. selector: "defaultController",
  332. category: 'factory',
  333. fn: function (){
  334. var self=this;
  335. return smalltalk.withContext(function($ctx1) {
  336. var $1;
  337. $1=_st(self._defaultControllerClass())._new();
  338. return $1;
  339. }, function($ctx1) {$ctx1.fill(self,"defaultController",{},smalltalk.MKView)})},
  340. args: [],
  341. source: "defaultController\x0a\x09^ self defaultControllerClass new",
  342. messageSends: ["new", "defaultControllerClass"],
  343. referencedClasses: []
  344. }),
  345. smalltalk.MKView);
  346. smalltalk.addMethod(
  347. smalltalk.method({
  348. selector: "defaultControllerClass",
  349. category: 'defaults',
  350. fn: function (){
  351. var self=this;
  352. function $MKController(){return smalltalk.MKController||(typeof MKController=="undefined"?nil:MKController)}
  353. return smalltalk.withContext(function($ctx1) {
  354. var $1;
  355. $1=$MKController();
  356. return $1;
  357. }, function($ctx1) {$ctx1.fill(self,"defaultControllerClass",{},smalltalk.MKView)})},
  358. args: [],
  359. source: "defaultControllerClass\x0a\x09^ MKController",
  360. messageSends: [],
  361. referencedClasses: ["MKController"]
  362. }),
  363. smalltalk.MKView);
  364. smalltalk.addMethod(
  365. smalltalk.method({
  366. selector: "model",
  367. category: 'accessing',
  368. fn: function (){
  369. var self=this;
  370. return smalltalk.withContext(function($ctx1) {
  371. var $1;
  372. $1=self["@model"];
  373. return $1;
  374. }, function($ctx1) {$ctx1.fill(self,"model",{},smalltalk.MKView)})},
  375. args: [],
  376. source: "model\x0a\x09^ model",
  377. messageSends: [],
  378. referencedClasses: []
  379. }),
  380. smalltalk.MKView);
  381. smalltalk.addMethod(
  382. smalltalk.method({
  383. selector: "model:",
  384. category: 'accessing',
  385. fn: function (aModel){
  386. var self=this;
  387. return smalltalk.withContext(function($ctx1) {
  388. self["@model"]=aModel;
  389. self._observeModel();
  390. return self}, function($ctx1) {$ctx1.fill(self,"model:",{aModel:aModel},smalltalk.MKView)})},
  391. args: ["aModel"],
  392. source: "model: aModel\x0a\x09model := aModel.\x0a\x09self observeModel",
  393. messageSends: ["observeModel"],
  394. referencedClasses: []
  395. }),
  396. smalltalk.MKView);
  397. smalltalk.addMethod(
  398. smalltalk.method({
  399. selector: "observeModel",
  400. category: 'observing',
  401. fn: function (){
  402. var self=this;
  403. return smalltalk.withContext(function($ctx1) {
  404. return self}, function($ctx1) {$ctx1.fill(self,"observeModel",{},smalltalk.MKView)})},
  405. args: [],
  406. source: "observeModel\x0a\x09\x22No op. Override in subclasses\x22",
  407. messageSends: [],
  408. referencedClasses: []
  409. }),
  410. smalltalk.MKView);
  411. smalltalk.addMethod(
  412. smalltalk.method({
  413. selector: "render",
  414. category: 'rendering',
  415. fn: function (){
  416. var self=this;
  417. return smalltalk.withContext(function($ctx1) {
  418. self._appendToJQuery_("body"._asJQuery());
  419. return self}, function($ctx1) {$ctx1.fill(self,"render",{},smalltalk.MKView)})},
  420. args: [],
  421. source: "render\x0a\x09\x22Append the receiver to the BODY element\x22\x0a\x09\x0a\x09self appendToJQuery: 'body' asJQuery",
  422. messageSends: ["appendToJQuery:", "asJQuery"],
  423. referencedClasses: []
  424. }),
  425. smalltalk.MKView);
  426. smalltalk.addMethod(
  427. smalltalk.method({
  428. selector: "renderContentOn:",
  429. category: 'rendering',
  430. fn: function (html){
  431. var self=this;
  432. return smalltalk.withContext(function($ctx1) {
  433. return self}, function($ctx1) {$ctx1.fill(self,"renderContentOn:",{html:html},smalltalk.MKView)})},
  434. args: ["html"],
  435. source: "renderContentOn: html\x0a\x09\x22Main rendering method, override in subclasses.\x22",
  436. messageSends: [],
  437. referencedClasses: []
  438. }),
  439. smalltalk.MKView);
  440. smalltalk.addMethod(
  441. smalltalk.method({
  442. selector: "renderOn:",
  443. category: 'rendering',
  444. fn: function (html){
  445. var self=this;
  446. return smalltalk.withContext(function($ctx1) {
  447. var $1,$2;
  448. $1=_st(html)._div();
  449. _st($1)._class_("moka_view");
  450. $2=_st($1)._yourself();
  451. self["@wrapper"]=$2;
  452. _st(self["@wrapper"])._with_((function(){
  453. return smalltalk.withContext(function($ctx2) {
  454. return self._renderContentOn_(html);
  455. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  456. return self}, function($ctx1) {$ctx1.fill(self,"renderOn:",{html:html},smalltalk.MKView)})},
  457. args: ["html"],
  458. source: "renderOn: html\x0a\x09\x22Basic rendering method.\x0a\x09Wraps the content with a `wrapper` div for updating the receiver.\x0a\x09\x0a\x09Do not override this method, but `#renderContentOn:`\x22\x0a\x09\x0a\x09wrapper := html div\x0a\x09\x09class: 'moka_view';\x0a\x09\x09yourself.\x0a\x09wrapper with: [ self renderContentOn: html ]",
  459. messageSends: ["class:", "div", "yourself", "with:", "renderContentOn:"],
  460. referencedClasses: []
  461. }),
  462. smalltalk.MKView);
  463. smalltalk.addMethod(
  464. smalltalk.method({
  465. selector: "update",
  466. category: 'updating',
  467. fn: function (){
  468. var self=this;
  469. return smalltalk.withContext(function($ctx1) {
  470. var $1,$2,$3,$4;
  471. $1=self["@wrapper"];
  472. if(($receiver = $1) == nil || $receiver == null){
  473. self._error_("The view has not been rendered yet");
  474. } else {
  475. $1;
  476. };
  477. $2=_st(self["@wrapper"])._asJQuery();
  478. $ctx1.sendIdx["asJQuery"]=1;
  479. _st($2)._empty();
  480. $3=(function(html){
  481. return smalltalk.withContext(function($ctx2) {
  482. return self._renderContentOn_(html);
  483. }, function($ctx2) {$ctx2.fillBlock({html:html},$ctx1,2)})});
  484. $4=_st(self["@wrapper"])._asJQuery();
  485. _st($3)._appendToJQuery_($4);
  486. return self}, function($ctx1) {$ctx1.fill(self,"update",{},smalltalk.MKView)})},
  487. args: [],
  488. source: "update\x0a\x09\x22Update the view's content.\x22\x0a\x09\x0a\x09wrapper ifNil: [ self error: 'The view has not been rendered yet' ].\x0a\x09\x0a\x09wrapper asJQuery empty.\x0a\x09[ :html | self renderContentOn: html ] \x0a\x09\x09appendToJQuery: wrapper asJQuery",
  489. messageSends: ["ifNil:", "error:", "empty", "asJQuery", "appendToJQuery:", "renderContentOn:"],
  490. referencedClasses: []
  491. }),
  492. smalltalk.MKView);
  493. smalltalk.addMethod(
  494. smalltalk.method({
  495. selector: "model:",
  496. category: 'instance creation',
  497. fn: function (aModel){
  498. var self=this;
  499. return smalltalk.withContext(function($ctx1) {
  500. var $2,$3,$1;
  501. $2=self._new();
  502. _st($2)._model_(aModel);
  503. $3=_st($2)._yourself();
  504. $1=$3;
  505. return $1;
  506. }, function($ctx1) {$ctx1.fill(self,"model:",{aModel:aModel},smalltalk.MKView.klass)})},
  507. args: ["aModel"],
  508. source: "model: aModel\x0a\x09^ self new\x0a\x09\x09model: aModel;\x0a\x09\x09yourself",
  509. messageSends: ["model:", "new", "yourself"],
  510. referencedClasses: []
  511. }),
  512. smalltalk.MKView.klass);
  513. smalltalk.addMethod(
  514. smalltalk.method({
  515. selector: "model:controller:",
  516. category: 'instance creation',
  517. fn: function (aModel,aController){
  518. var self=this;
  519. return smalltalk.withContext(function($ctx1) {
  520. var $2,$3,$1;
  521. $2=self._model_(aModel);
  522. _st($2)._controller_(aController);
  523. $3=_st($2)._yourself();
  524. $1=$3;
  525. return $1;
  526. }, function($ctx1) {$ctx1.fill(self,"model:controller:",{aModel:aModel,aController:aController},smalltalk.MKView.klass)})},
  527. args: ["aModel", "aController"],
  528. source: "model: aModel controller: aController\x0a\x09^ (self model: aModel)\x0a\x09\x09controller: aController;\x0a\x09\x09yourself",
  529. messageSends: ["controller:", "model:", "yourself"],
  530. referencedClasses: []
  531. }),
  532. smalltalk.MKView.klass);
  533. smalltalk.addClass('MKAspectView', smalltalk.MKView, ['aspect', 'label'], 'Moka-Core');
  534. smalltalk.MKAspectView.comment="I am an abstract view which state depend on an `aspect` of a model. \x0a\x0a##API\x0a\x0a- Use the `#aspect:` to listen to a specific aspect of a model. Changes will then trigger `#update`.";
  535. smalltalk.addMethod(
  536. smalltalk.method({
  537. selector: "aspect",
  538. category: 'accessing',
  539. fn: function (){
  540. var self=this;
  541. return smalltalk.withContext(function($ctx1) {
  542. var $1;
  543. $1=self["@aspect"];
  544. return $1;
  545. }, function($ctx1) {$ctx1.fill(self,"aspect",{},smalltalk.MKAspectView)})},
  546. args: [],
  547. source: "aspect\x0a\x09^ aspect",
  548. messageSends: [],
  549. referencedClasses: []
  550. }),
  551. smalltalk.MKAspectView);
  552. smalltalk.addMethod(
  553. smalltalk.method({
  554. selector: "aspect:",
  555. category: 'accessing',
  556. fn: function (aSelector){
  557. var self=this;
  558. return smalltalk.withContext(function($ctx1) {
  559. self["@aspect"]=aSelector;
  560. _st(self._controller())._aspect_(aSelector);
  561. return self}, function($ctx1) {$ctx1.fill(self,"aspect:",{aSelector:aSelector},smalltalk.MKAspectView)})},
  562. args: ["aSelector"],
  563. source: "aspect: aSelector\x0a\x09aspect := aSelector.\x0a\x09self controller aspect: aSelector",
  564. messageSends: ["aspect:", "controller"],
  565. referencedClasses: []
  566. }),
  567. smalltalk.MKAspectView);
  568. smalltalk.addMethod(
  569. smalltalk.method({
  570. selector: "aspectValue",
  571. category: 'accessing',
  572. fn: function (){
  573. var self=this;
  574. return smalltalk.withContext(function($ctx1) {
  575. var $1;
  576. $1=_st(self._model())._perform_(self._aspect());
  577. return $1;
  578. }, function($ctx1) {$ctx1.fill(self,"aspectValue",{},smalltalk.MKAspectView)})},
  579. args: [],
  580. source: "aspectValue\x0a\x09^ self model perform: self aspect",
  581. messageSends: ["perform:", "model", "aspect"],
  582. referencedClasses: []
  583. }),
  584. smalltalk.MKAspectView);
  585. smalltalk.addMethod(
  586. smalltalk.method({
  587. selector: "defaultControllerClass",
  588. category: 'defaults',
  589. fn: function (){
  590. var self=this;
  591. function $MKAspectController(){return smalltalk.MKAspectController||(typeof MKAspectController=="undefined"?nil:MKAspectController)}
  592. return smalltalk.withContext(function($ctx1) {
  593. return $MKAspectController();
  594. }, function($ctx1) {$ctx1.fill(self,"defaultControllerClass",{},smalltalk.MKAspectView)})},
  595. args: [],
  596. source: "defaultControllerClass\x0a\x09^ MKAspectController",
  597. messageSends: [],
  598. referencedClasses: ["MKAspectController"]
  599. }),
  600. smalltalk.MKAspectView);
  601. smalltalk.addMethod(
  602. smalltalk.method({
  603. selector: "observeModel",
  604. category: 'observing',
  605. fn: function (){
  606. var self=this;
  607. function $MKModelChanged(){return smalltalk.MKModelChanged||(typeof MKModelChanged=="undefined"?nil:MKModelChanged)}
  608. return smalltalk.withContext(function($ctx1) {
  609. smalltalk.MKAspectView.superclass.fn.prototype._observeModel.apply(_st(self), []);
  610. _st(self._model())._on_send_to_($MKModelChanged(),"update:",self);
  611. return self}, function($ctx1) {$ctx1.fill(self,"observeModel",{},smalltalk.MKAspectView)})},
  612. args: [],
  613. source: "observeModel\x0a\x09super observeModel.\x0a\x09\x0a\x09self model\x0a\x09\x09on: MKModelChanged\x0a\x09\x09send: 'update:'\x0a\x09\x09to: self",
  614. messageSends: ["observeModel", "on:send:to:", "model"],
  615. referencedClasses: ["MKModelChanged"]
  616. }),
  617. smalltalk.MKAspectView);
  618. smalltalk.addMethod(
  619. smalltalk.method({
  620. selector: "update:",
  621. category: 'updating',
  622. fn: function (anAnnouncement){
  623. var self=this;
  624. return smalltalk.withContext(function($ctx1) {
  625. var $2,$1;
  626. $2=_st(anAnnouncement)._aspect();
  627. $ctx1.sendIdx["aspect"]=1;
  628. $1=_st($2).__eq(self._aspect());
  629. if(smalltalk.assert($1)){
  630. self._update();
  631. };
  632. return self}, function($ctx1) {$ctx1.fill(self,"update:",{anAnnouncement:anAnnouncement},smalltalk.MKAspectView)})},
  633. args: ["anAnnouncement"],
  634. source: "update: anAnnouncement\x0a\x09anAnnouncement aspect = self aspect\x0a\x09\x09ifTrue: [ self update ]",
  635. messageSends: ["ifTrue:", "=", "aspect", "update"],
  636. referencedClasses: []
  637. }),
  638. smalltalk.MKAspectView);
  639. smalltalk.addMethod(
  640. smalltalk.method({
  641. selector: "model:aspect:",
  642. category: 'instance creation',
  643. fn: function (aModel,aSelector){
  644. var self=this;
  645. return smalltalk.withContext(function($ctx1) {
  646. var $2,$3,$1;
  647. $2=self._model_(aModel);
  648. _st($2)._aspect_(aSelector);
  649. $3=_st($2)._yourself();
  650. $1=$3;
  651. return $1;
  652. }, function($ctx1) {$ctx1.fill(self,"model:aspect:",{aModel:aModel,aSelector:aSelector},smalltalk.MKAspectView.klass)})},
  653. args: ["aModel", "aSelector"],
  654. source: "model: aModel aspect: aSelector\x0a\x09^ (self model: aModel)\x0a\x09\x09aspect: aSelector;\x0a\x09\x09yourself",
  655. messageSends: ["aspect:", "model:", "yourself"],
  656. referencedClasses: []
  657. }),
  658. smalltalk.MKAspectView.klass);
  659. });