Moka-Core.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  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,$2,$4,$3;
  136. $1=self._aspect();
  137. $ctx1.sendIdx["aspect"]=1;
  138. if(($receiver = $1) == nil || $receiver == null){
  139. $1;
  140. } else {
  141. $2=self._model();
  142. $4=self._aspect();
  143. $3=_st($4)._asMutator();
  144. _st($2)._perform_withArguments_($3,[anObject]);
  145. };
  146. return self}, function($ctx1) {$ctx1.fill(self,"performActionWith:",{anObject:anObject},smalltalk.MKAspectController)})},
  147. args: ["anObject"],
  148. source: "performActionWith: anObject\x0a\x09self aspect ifNotNil: [\x0a\x09\x09self model \x0a\x09\x09\x09perform: self aspect asMutator\x0a\x09\x09\x09withArguments: { anObject } ]",
  149. messageSends: ["ifNotNil:", "aspect", "perform:withArguments:", "model", "asMutator"],
  150. referencedClasses: []
  151. }),
  152. smalltalk.MKAspectController);
  153. smalltalk.addClass('MKModel', smalltalk.Object, ['announcer'], 'Moka-Core');
  154. 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.";
  155. smalltalk.addMethod(
  156. smalltalk.method({
  157. selector: "announce:",
  158. category: 'announcements',
  159. fn: function (anAnnouncement){
  160. var self=this;
  161. return smalltalk.withContext(function($ctx1) {
  162. _st(self["@announcer"])._announce_(anAnnouncement);
  163. return self}, function($ctx1) {$ctx1.fill(self,"announce:",{anAnnouncement:anAnnouncement},smalltalk.MKModel)})},
  164. args: ["anAnnouncement"],
  165. source: "announce: anAnnouncement\x0a\x09announcer announce: anAnnouncement",
  166. messageSends: ["announce:"],
  167. referencedClasses: []
  168. }),
  169. smalltalk.MKModel);
  170. smalltalk.addMethod(
  171. smalltalk.method({
  172. selector: "changed:",
  173. category: 'announcements',
  174. fn: function (aSelector){
  175. var self=this;
  176. function $MKModelChanged(){return smalltalk.MKModelChanged||(typeof MKModelChanged=="undefined"?nil:MKModelChanged)}
  177. return smalltalk.withContext(function($ctx1) {
  178. self._announce_(_st($MKModelChanged())._aspect_(aSelector));
  179. return self}, function($ctx1) {$ctx1.fill(self,"changed:",{aSelector:aSelector},smalltalk.MKModel)})},
  180. args: ["aSelector"],
  181. source: "changed: aSelector\x0a\x09\x22Trigger `#update:` to all listening aspect views\x22\x0a\x09\x0a\x09self announce: (MKModelChanged aspect: aSelector)",
  182. messageSends: ["announce:", "aspect:"],
  183. referencedClasses: ["MKModelChanged"]
  184. }),
  185. smalltalk.MKModel);
  186. smalltalk.addMethod(
  187. smalltalk.method({
  188. selector: "initialize",
  189. category: 'initialization',
  190. fn: function (){
  191. var self=this;
  192. function $Announcer(){return smalltalk.Announcer||(typeof Announcer=="undefined"?nil:Announcer)}
  193. return smalltalk.withContext(function($ctx1) {
  194. smalltalk.MKModel.superclass.fn.prototype._initialize.apply(_st(self), []);
  195. self["@announcer"]=_st($Announcer())._new();
  196. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.MKModel)})},
  197. args: [],
  198. source: "initialize\x0a\x09super initialize.\x0a\x09announcer := Announcer new",
  199. messageSends: ["initialize", "new"],
  200. referencedClasses: ["Announcer"]
  201. }),
  202. smalltalk.MKModel);
  203. smalltalk.addMethod(
  204. smalltalk.method({
  205. selector: "on:do:",
  206. category: 'announcements',
  207. fn: function (anAnnouncement,aBlock){
  208. var self=this;
  209. return smalltalk.withContext(function($ctx1) {
  210. _st(self["@announcer"])._on_do_(anAnnouncement,aBlock);
  211. return self}, function($ctx1) {$ctx1.fill(self,"on:do:",{anAnnouncement:anAnnouncement,aBlock:aBlock},smalltalk.MKModel)})},
  212. args: ["anAnnouncement", "aBlock"],
  213. source: "on: anAnnouncement do: aBlock\x0a\x09announcer on: anAnnouncement do: aBlock",
  214. messageSends: ["on:do:"],
  215. referencedClasses: []
  216. }),
  217. smalltalk.MKModel);
  218. smalltalk.addMethod(
  219. smalltalk.method({
  220. selector: "on:send:to:",
  221. category: 'announcements',
  222. fn: function (anAnnouncement,aSelector,anObject){
  223. var self=this;
  224. return smalltalk.withContext(function($ctx1) {
  225. _st(self["@announcer"])._on_send_to_(anAnnouncement,aSelector,anObject);
  226. return self}, function($ctx1) {$ctx1.fill(self,"on:send:to:",{anAnnouncement:anAnnouncement,aSelector:aSelector,anObject:anObject},smalltalk.MKModel)})},
  227. args: ["anAnnouncement", "aSelector", "anObject"],
  228. source: "on: anAnnouncement send: aSelector to: anObject\x0a\x09announcer on: anAnnouncement send: aSelector to: anObject",
  229. messageSends: ["on:send:to:"],
  230. referencedClasses: []
  231. }),
  232. smalltalk.MKModel);
  233. smalltalk.addClass('MKModelChanged', smalltalk.Object, ['aspect'], 'Moka-Core');
  234. smalltalk.MKModelChanged.comment="I am an announcement announced when a model is changed.";
  235. smalltalk.addMethod(
  236. smalltalk.method({
  237. selector: "aspect",
  238. category: 'accessing',
  239. fn: function (){
  240. var self=this;
  241. return smalltalk.withContext(function($ctx1) {
  242. var $1;
  243. $1=self["@aspect"];
  244. return $1;
  245. }, function($ctx1) {$ctx1.fill(self,"aspect",{},smalltalk.MKModelChanged)})},
  246. args: [],
  247. source: "aspect\x0a\x09^ aspect",
  248. messageSends: [],
  249. referencedClasses: []
  250. }),
  251. smalltalk.MKModelChanged);
  252. smalltalk.addMethod(
  253. smalltalk.method({
  254. selector: "aspect:",
  255. category: 'accessing',
  256. fn: function (aSelector){
  257. var self=this;
  258. return smalltalk.withContext(function($ctx1) {
  259. self["@aspect"]=aSelector;
  260. return self}, function($ctx1) {$ctx1.fill(self,"aspect:",{aSelector:aSelector},smalltalk.MKModelChanged)})},
  261. args: ["aSelector"],
  262. source: "aspect: aSelector\x0a\x09aspect := aSelector",
  263. messageSends: [],
  264. referencedClasses: []
  265. }),
  266. smalltalk.MKModelChanged);
  267. smalltalk.addMethod(
  268. smalltalk.method({
  269. selector: "aspect:",
  270. category: 'instance creation',
  271. fn: function (aSelector){
  272. var self=this;
  273. return smalltalk.withContext(function($ctx1) {
  274. var $2,$3,$1;
  275. $2=self._new();
  276. _st($2)._aspect_(aSelector);
  277. $3=_st($2)._yourself();
  278. $1=$3;
  279. return $1;
  280. }, function($ctx1) {$ctx1.fill(self,"aspect:",{aSelector:aSelector},smalltalk.MKModelChanged.klass)})},
  281. args: ["aSelector"],
  282. source: "aspect: aSelector\x0a\x09^ self new\x0a\x09\x09aspect: aSelector;\x0a\x09\x09yourself",
  283. messageSends: ["aspect:", "new", "yourself"],
  284. referencedClasses: []
  285. }),
  286. smalltalk.MKModelChanged.klass);
  287. smalltalk.addClass('MKView', smalltalk.Widget, ['controller', 'model', 'wrapper'], 'Moka-Core');
  288. 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`.";
  289. smalltalk.addMethod(
  290. smalltalk.method({
  291. selector: "controller",
  292. category: 'accessing',
  293. fn: function (){
  294. var self=this;
  295. return smalltalk.withContext(function($ctx1) {
  296. var $1,$2;
  297. $1=self["@controller"];
  298. if(($receiver = $1) == nil || $receiver == null){
  299. self._controller_(self._defaultController());
  300. } else {
  301. $1;
  302. };
  303. $2=self["@controller"];
  304. return $2;
  305. }, function($ctx1) {$ctx1.fill(self,"controller",{},smalltalk.MKView)})},
  306. args: [],
  307. 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",
  308. messageSends: ["ifNil:", "controller:", "defaultController"],
  309. referencedClasses: []
  310. }),
  311. smalltalk.MKView);
  312. smalltalk.addMethod(
  313. smalltalk.method({
  314. selector: "controller:",
  315. category: 'accessing',
  316. fn: function (aController){
  317. var self=this;
  318. return smalltalk.withContext(function($ctx1) {
  319. var $1,$2;
  320. self["@controller"]=aController;
  321. $1=aController;
  322. _st($1)._view_(self);
  323. $2=_st($1)._model_(self._model());
  324. return self}, function($ctx1) {$ctx1.fill(self,"controller:",{aController:aController},smalltalk.MKView)})},
  325. args: ["aController"],
  326. 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",
  327. messageSends: ["view:", "model:", "model"],
  328. referencedClasses: []
  329. }),
  330. smalltalk.MKView);
  331. smalltalk.addMethod(
  332. smalltalk.method({
  333. selector: "defaultController",
  334. category: 'factory',
  335. fn: function (){
  336. var self=this;
  337. return smalltalk.withContext(function($ctx1) {
  338. var $1;
  339. $1=_st(self._defaultControllerClass())._new();
  340. return $1;
  341. }, function($ctx1) {$ctx1.fill(self,"defaultController",{},smalltalk.MKView)})},
  342. args: [],
  343. source: "defaultController\x0a\x09^ self defaultControllerClass new",
  344. messageSends: ["new", "defaultControllerClass"],
  345. referencedClasses: []
  346. }),
  347. smalltalk.MKView);
  348. smalltalk.addMethod(
  349. smalltalk.method({
  350. selector: "defaultControllerClass",
  351. category: 'defaults',
  352. fn: function (){
  353. var self=this;
  354. function $MKController(){return smalltalk.MKController||(typeof MKController=="undefined"?nil:MKController)}
  355. return smalltalk.withContext(function($ctx1) {
  356. var $1;
  357. $1=$MKController();
  358. return $1;
  359. }, function($ctx1) {$ctx1.fill(self,"defaultControllerClass",{},smalltalk.MKView)})},
  360. args: [],
  361. source: "defaultControllerClass\x0a\x09^ MKController",
  362. messageSends: [],
  363. referencedClasses: ["MKController"]
  364. }),
  365. smalltalk.MKView);
  366. smalltalk.addMethod(
  367. smalltalk.method({
  368. selector: "model",
  369. category: 'accessing',
  370. fn: function (){
  371. var self=this;
  372. return smalltalk.withContext(function($ctx1) {
  373. var $1;
  374. $1=self["@model"];
  375. return $1;
  376. }, function($ctx1) {$ctx1.fill(self,"model",{},smalltalk.MKView)})},
  377. args: [],
  378. source: "model\x0a\x09^ model",
  379. messageSends: [],
  380. referencedClasses: []
  381. }),
  382. smalltalk.MKView);
  383. smalltalk.addMethod(
  384. smalltalk.method({
  385. selector: "model:",
  386. category: 'accessing',
  387. fn: function (aModel){
  388. var self=this;
  389. return smalltalk.withContext(function($ctx1) {
  390. self["@model"]=aModel;
  391. self._observeModel();
  392. return self}, function($ctx1) {$ctx1.fill(self,"model:",{aModel:aModel},smalltalk.MKView)})},
  393. args: ["aModel"],
  394. source: "model: aModel\x0a\x09model := aModel.\x0a\x09self observeModel",
  395. messageSends: ["observeModel"],
  396. referencedClasses: []
  397. }),
  398. smalltalk.MKView);
  399. smalltalk.addMethod(
  400. smalltalk.method({
  401. selector: "observeModel",
  402. category: 'observing',
  403. fn: function (){
  404. var self=this;
  405. return smalltalk.withContext(function($ctx1) {
  406. return self}, function($ctx1) {$ctx1.fill(self,"observeModel",{},smalltalk.MKView)})},
  407. args: [],
  408. source: "observeModel\x0a\x09\x22No op. Override in subclasses\x22",
  409. messageSends: [],
  410. referencedClasses: []
  411. }),
  412. smalltalk.MKView);
  413. smalltalk.addMethod(
  414. smalltalk.method({
  415. selector: "render",
  416. category: 'rendering',
  417. fn: function (){
  418. var self=this;
  419. return smalltalk.withContext(function($ctx1) {
  420. self._appendToJQuery_("body"._asJQuery());
  421. return self}, function($ctx1) {$ctx1.fill(self,"render",{},smalltalk.MKView)})},
  422. args: [],
  423. source: "render\x0a\x09\x22Append the receiver to the BODY element\x22\x0a\x09\x0a\x09self appendToJQuery: 'body' asJQuery",
  424. messageSends: ["appendToJQuery:", "asJQuery"],
  425. referencedClasses: []
  426. }),
  427. smalltalk.MKView);
  428. smalltalk.addMethod(
  429. smalltalk.method({
  430. selector: "renderContentOn:",
  431. category: 'rendering',
  432. fn: function (html){
  433. var self=this;
  434. return smalltalk.withContext(function($ctx1) {
  435. return self}, function($ctx1) {$ctx1.fill(self,"renderContentOn:",{html:html},smalltalk.MKView)})},
  436. args: ["html"],
  437. source: "renderContentOn: html\x0a\x09\x22Main rendering method, override in subclasses.\x22",
  438. messageSends: [],
  439. referencedClasses: []
  440. }),
  441. smalltalk.MKView);
  442. smalltalk.addMethod(
  443. smalltalk.method({
  444. selector: "renderOn:",
  445. category: 'rendering',
  446. fn: function (html){
  447. var self=this;
  448. return smalltalk.withContext(function($ctx1) {
  449. var $1,$2;
  450. $1=_st(html)._div();
  451. _st($1)._class_("moka_view");
  452. $2=_st($1)._yourself();
  453. self["@wrapper"]=$2;
  454. _st(self["@wrapper"])._with_((function(){
  455. return smalltalk.withContext(function($ctx2) {
  456. return self._renderContentOn_(html);
  457. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  458. return self}, function($ctx1) {$ctx1.fill(self,"renderOn:",{html:html},smalltalk.MKView)})},
  459. args: ["html"],
  460. 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 ]",
  461. messageSends: ["class:", "div", "yourself", "with:", "renderContentOn:"],
  462. referencedClasses: []
  463. }),
  464. smalltalk.MKView);
  465. smalltalk.addMethod(
  466. smalltalk.method({
  467. selector: "update",
  468. category: 'updating',
  469. fn: function (){
  470. var self=this;
  471. return smalltalk.withContext(function($ctx1) {
  472. var $1,$2,$3,$4;
  473. $1=self["@wrapper"];
  474. if(($receiver = $1) == nil || $receiver == null){
  475. self._error_("The view has not been rendered yet");
  476. } else {
  477. $1;
  478. };
  479. $2=_st(self["@wrapper"])._asJQuery();
  480. $ctx1.sendIdx["asJQuery"]=1;
  481. _st($2)._empty();
  482. $3=(function(html){
  483. return smalltalk.withContext(function($ctx2) {
  484. return self._renderContentOn_(html);
  485. }, function($ctx2) {$ctx2.fillBlock({html:html},$ctx1,2)})});
  486. $4=_st(self["@wrapper"])._asJQuery();
  487. _st($3)._appendToJQuery_($4);
  488. return self}, function($ctx1) {$ctx1.fill(self,"update",{},smalltalk.MKView)})},
  489. args: [],
  490. 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",
  491. messageSends: ["ifNil:", "error:", "empty", "asJQuery", "appendToJQuery:", "renderContentOn:"],
  492. referencedClasses: []
  493. }),
  494. smalltalk.MKView);
  495. smalltalk.addMethod(
  496. smalltalk.method({
  497. selector: "model:",
  498. category: 'instance creation',
  499. fn: function (aModel){
  500. var self=this;
  501. return smalltalk.withContext(function($ctx1) {
  502. var $2,$3,$1;
  503. $2=self._new();
  504. _st($2)._model_(aModel);
  505. $3=_st($2)._yourself();
  506. $1=$3;
  507. return $1;
  508. }, function($ctx1) {$ctx1.fill(self,"model:",{aModel:aModel},smalltalk.MKView.klass)})},
  509. args: ["aModel"],
  510. source: "model: aModel\x0a\x09^ self new\x0a\x09\x09model: aModel;\x0a\x09\x09yourself",
  511. messageSends: ["model:", "new", "yourself"],
  512. referencedClasses: []
  513. }),
  514. smalltalk.MKView.klass);
  515. smalltalk.addMethod(
  516. smalltalk.method({
  517. selector: "model:controller:",
  518. category: 'instance creation',
  519. fn: function (aModel,aController){
  520. var self=this;
  521. return smalltalk.withContext(function($ctx1) {
  522. var $2,$3,$1;
  523. $2=self._model_(aModel);
  524. _st($2)._controller_(aController);
  525. $3=_st($2)._yourself();
  526. $1=$3;
  527. return $1;
  528. }, function($ctx1) {$ctx1.fill(self,"model:controller:",{aModel:aModel,aController:aController},smalltalk.MKView.klass)})},
  529. args: ["aModel", "aController"],
  530. source: "model: aModel controller: aController\x0a\x09^ (self model: aModel)\x0a\x09\x09controller: aController;\x0a\x09\x09yourself",
  531. messageSends: ["controller:", "model:", "yourself"],
  532. referencedClasses: []
  533. }),
  534. smalltalk.MKView.klass);
  535. smalltalk.addClass('MKAspectView', smalltalk.MKView, ['aspect', 'label'], 'Moka-Core');
  536. 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`.";
  537. smalltalk.addMethod(
  538. smalltalk.method({
  539. selector: "aspect",
  540. category: 'accessing',
  541. fn: function (){
  542. var self=this;
  543. return smalltalk.withContext(function($ctx1) {
  544. var $1;
  545. $1=self["@aspect"];
  546. return $1;
  547. }, function($ctx1) {$ctx1.fill(self,"aspect",{},smalltalk.MKAspectView)})},
  548. args: [],
  549. source: "aspect\x0a\x09^ aspect",
  550. messageSends: [],
  551. referencedClasses: []
  552. }),
  553. smalltalk.MKAspectView);
  554. smalltalk.addMethod(
  555. smalltalk.method({
  556. selector: "aspect:",
  557. category: 'accessing',
  558. fn: function (aSelector){
  559. var self=this;
  560. return smalltalk.withContext(function($ctx1) {
  561. self["@aspect"]=aSelector;
  562. _st(self._controller())._aspect_(aSelector);
  563. return self}, function($ctx1) {$ctx1.fill(self,"aspect:",{aSelector:aSelector},smalltalk.MKAspectView)})},
  564. args: ["aSelector"],
  565. source: "aspect: aSelector\x0a\x09aspect := aSelector.\x0a\x09self controller aspect: aSelector",
  566. messageSends: ["aspect:", "controller"],
  567. referencedClasses: []
  568. }),
  569. smalltalk.MKAspectView);
  570. smalltalk.addMethod(
  571. smalltalk.method({
  572. selector: "aspectValue",
  573. category: 'accessing',
  574. fn: function (){
  575. var self=this;
  576. return smalltalk.withContext(function($ctx1) {
  577. var $1;
  578. $1=_st(self._model())._perform_(self._aspect());
  579. return $1;
  580. }, function($ctx1) {$ctx1.fill(self,"aspectValue",{},smalltalk.MKAspectView)})},
  581. args: [],
  582. source: "aspectValue\x0a\x09^ self model perform: self aspect",
  583. messageSends: ["perform:", "model", "aspect"],
  584. referencedClasses: []
  585. }),
  586. smalltalk.MKAspectView);
  587. smalltalk.addMethod(
  588. smalltalk.method({
  589. selector: "observeModel",
  590. category: 'observing',
  591. fn: function (){
  592. var self=this;
  593. function $MKModelChanged(){return smalltalk.MKModelChanged||(typeof MKModelChanged=="undefined"?nil:MKModelChanged)}
  594. return smalltalk.withContext(function($ctx1) {
  595. smalltalk.MKAspectView.superclass.fn.prototype._observeModel.apply(_st(self), []);
  596. _st(self._model())._on_send_to_($MKModelChanged(),"update:",self);
  597. return self}, function($ctx1) {$ctx1.fill(self,"observeModel",{},smalltalk.MKAspectView)})},
  598. args: [],
  599. source: "observeModel\x0a\x09super observeModel.\x0a\x09\x0a\x09self model\x0a\x09\x09on: MKModelChanged\x0a\x09\x09send: 'update:'\x0a\x09\x09to: self",
  600. messageSends: ["observeModel", "on:send:to:", "model"],
  601. referencedClasses: ["MKModelChanged"]
  602. }),
  603. smalltalk.MKAspectView);
  604. smalltalk.addMethod(
  605. smalltalk.method({
  606. selector: "update:",
  607. category: 'updating',
  608. fn: function (anAnnouncement){
  609. var self=this;
  610. return smalltalk.withContext(function($ctx1) {
  611. var $2,$3,$1;
  612. $2=_st(anAnnouncement)._aspect();
  613. $ctx1.sendIdx["aspect"]=1;
  614. $3=self._aspect();
  615. $1=_st($2).__eq($3);
  616. if(smalltalk.assert($1)){
  617. self._update();
  618. };
  619. return self}, function($ctx1) {$ctx1.fill(self,"update:",{anAnnouncement:anAnnouncement},smalltalk.MKAspectView)})},
  620. args: ["anAnnouncement"],
  621. source: "update: anAnnouncement\x0a\x09anAnnouncement aspect = self aspect\x0a\x09\x09ifTrue: [ self update ]",
  622. messageSends: ["ifTrue:", "=", "aspect", "update"],
  623. referencedClasses: []
  624. }),
  625. smalltalk.MKAspectView);
  626. smalltalk.addMethod(
  627. smalltalk.method({
  628. selector: "model:aspect:",
  629. category: 'instance creation',
  630. fn: function (aModel,aSelector){
  631. var self=this;
  632. return smalltalk.withContext(function($ctx1) {
  633. var $2,$3,$1;
  634. $2=self._model_(aModel);
  635. _st($2)._aspect_(aSelector);
  636. $3=_st($2)._yourself();
  637. $1=$3;
  638. return $1;
  639. }, function($ctx1) {$ctx1.fill(self,"model:aspect:",{aModel:aModel,aSelector:aSelector},smalltalk.MKAspectView.klass)})},
  640. args: ["aModel", "aSelector"],
  641. source: "model: aModel aspect: aSelector\x0a\x09^ (self model: aModel)\x0a\x09\x09aspect: aSelector;\x0a\x09\x09yourself",
  642. messageSends: ["aspect:", "model:", "yourself"],
  643. referencedClasses: []
  644. }),
  645. smalltalk.MKAspectView.klass);
  646. });