ILIAS  release_8 Revision v8.23
with_js.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
19 function with_js()
20 {
21  global $DIC;
22  $f = $DIC->ui()->factory();
23  $renderer = $DIC->ui()->renderer();
24 
25  //Note that both counters have to be present to perform JS actions on them
26  $like = $f->symbol()->glyph()->love("#")
27  ->withCounter($f->counter()->novelty(3))
28  ->withCounter($f->counter()->status(0));
29 
30  $set_status_button = $f->button()->bulky($like, "Set Status Counter to 10 on click.", "#")
31  ->withAdditionalOnLoadCode(
32  function ($id) {
33  return "
34  $(\"#$id\").click(function() {
35  il.UI.counter.getCounterObject($(this)).setStatusTo(10);
36  });";
37  }
38  );
39 
40  $increment_novelty_button = $f->button()->bulky($like, "Increment Novelty Counter by on click", "#")
41  ->withAdditionalOnLoadCode(
42  function ($id) {
43  return "
44  $(\"#$id\").click(function() {
45  il.UI.counter.getCounterObject($(this)).incrementNoveltyCount(1);
46  });";
47  }
48  );
49 
50  $set_novelty_count_to_status_button = $f->button()->bulky($like, "Set Novelty Count to status on click", "#")
51  ->withAdditionalOnLoadCode(
52  function ($id) {
53  return "
54  $(\"#$id\").click(function() {
55  il.UI.counter.getCounterObject($(this)).setTotalNoveltyToStatusCount(1);
56  });";
57  }
58  );
59 
60  //What will the value of Status be after click?
61  $combined_button = $f->button()->bulky($like, "Some chained actions", "#")
62  ->withAdditionalOnLoadCode(
63  function ($id) {
64  return "
65  $(\"#$id\").click(function() {
66  var counter = il.UI.counter.getCounterObject($(this));
67  counter.setNoveltyTo(3);
68  counter.setStatusTo(3);
69  counter.incrementStatusCount(1);
70  counter.setTotalNoveltyToStatusCount();
71  console.log(
72  counter.getStatusCount()
73  );
74  });";
75  }
76  );
77 
78  return $renderer->render([$set_status_button,$increment_novelty_button,$set_novelty_count_to_status_button,$combined_button]);
79 }
global $DIC
Definition: feed.php:28
with_js()
Note, counters also offer an interface for manipulations through JS.
Definition: with_js.php:19
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23