Skip to content

Commit

Permalink
Send parameters to click action as object. Implemented enabled property.
Browse files Browse the repository at this point in the history
  • Loading branch information
ismcagdas committed Mar 29, 2017
1 parent 9d26131 commit 4609152
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions lib/extensions/jquery.jtable.record-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,17 @@
var $dropdownItemsContainer = $('<ul></ul>').addClass('dropdown-menu');
for (var i = 0; i < field.items.length; i++) {
var fieldItem = field.items[i];

if(fieldItem.visibility && !fieldItem.visibility(record)){
continue;

if(fieldItem.visible && !fieldItem.visible({record: record})){
continue;
}

var $dropdownItem = self._createDropdownItem(record, fieldItem);

if(fieldItem.enabled && !fieldItem.enabled({ record: record })){
$dropdownItem.addClass('disabled');
}

var $dropdownItem = self._createDropdownItem(record, field.items[i]);
$dropdownItem.appendTo($dropdownItemsContainer);
}

Expand All @@ -117,18 +122,20 @@
return $dropdownContainer;
},

_createDropdownItem: function(record, item){
_createDropdownItem: function(record, fieldItem){
var $li = $('<li></li>');
var $a = $('<a></a>');

if(item.text){
$a.html(item.text);
if(fieldItem.text){
$a.html(fieldItem.text);
}

if(item.action){
if(fieldItem.action && (fieldItem.enabled && fieldItem.enabled({ record: record }))) {
$a.click(function(){
item.action(record, $li.closest('tr'));
});
fieldItem.action({
record: record
});
});
}

$a.appendTo($li);
Expand Down

0 comments on commit 4609152

Please sign in to comment.