Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow arguments to jsModal #124

Merged
merged 5 commits into from
Apr 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion demos/modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ public function init()
$frame->add(['Header', 'Clicked row with ID = '.$_GET['id']]);
});

$t->on('click', 'tbody>tr', new \atk4\ui\jsModal(
$t->onRowClick(new \atk4\ui\jsModal('Row Clicked', $frame, ['id'=>$t->jsRow()->data('id')]));

// Old COMPAT code
/*
$t->on('click', 'tr', new \atk4\ui\jsModal(
'Row Clicked',
new \atk4\ui\jsExpression(
'[]+"&id="+[]', [
Expand All @@ -61,3 +65,4 @@ public function init()
)
));
$t->addStyle('cursor', 'pointer');
*/
29 changes: 29 additions & 0 deletions src/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,35 @@ public function renderView()
return View::renderView();
}

/**
* Same as on('click', 'tr', $action), but will also make sure you can't
* click outside of the body. Additionally when you move cursor over the
* rows, pointer will be used and rows will be highlighted as you hover.
*
* @param jsChain|callable $action Code to execute
*
* @return jQuery
*/
public function onRowClick($action)
{
$this->addClass('selectable');
$this->js(true)->find('tbody')->css('cursor', 'pointer');

return $this->on('click', 'tbody>tr', $action);
}

/**
* Use this to quickly access the <tr> and wrap in jQuery.
*
* $this->jsRow()->data('id');
*
* @return jQuery
*/
public function jsRow()
{
return new jQuery(new jsExpression('this'));
}

/**
* Executed for each row if "totals" are enabled to add up values.
*/
Expand Down
6 changes: 3 additions & 3 deletions src/jsModal.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
class jsModal extends jsExpression
{
public function __construct($title, $url)
public function __construct($title, $url, $args = [])
{
if ($url instanceof VirtualPage) {
$url = $url->getURL('cut');
Expand All @@ -29,7 +29,7 @@ public function __construct($title, $url)

parent::__construct('
var m=$("<div>").appendTo("body").addClass("ui fullscreen scrolling modal").html([content]);
m.modal({onHide: function() { m.children().remove(); return true; }}).modal("show").find(".content").load([url], function() { m.modal("refresh"); })',
['content'=>$content, 'url'=>$url]);
m.modal({onHide: function() { m.children().remove(); return true; }}).modal("show").find(".content").load([url], [arg], function() { m.modal("refresh"); })',
['content'=>$content, 'url'=>$url, 'arg'=>$args]);
}
}