Skip to content

Made events properly bubble #10

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

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 2 additions & 2 deletions Build/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.66.0")]
[assembly: AssemblyFileVersion("1.0.66.0")]
[assembly: AssemblyVersion("1.0.66.1")]
[assembly: AssemblyFileVersion("1.0.66.1")]
253 changes: 113 additions & 140 deletions Griddly/Scripts/griddly.js
Original file line number Diff line number Diff line change
Expand Up @@ -830,182 +830,155 @@
rowClickModal: null
};

var GriddlyButton = function (element, options) {
this.$element = $(element);
this.options = options;
function GriddlyButton()
{ }

this.create();
GriddlyButton.handleClick = $.proxy(function (event)
{
var button = $(event.currentTarget);
var griddly = button.closest("[data-role=griddly]");
var url = button.data("url");
var toggle = button.data("toggle");
var onclick = button.data("onclick");
var confirmMessage = button.data("confirm-message");
var enableOnSelection = button.data("enable-on-selection");

if ((typeof confirmMessage === "undefined" || confirm(confirmMessage)))
{
if (button.triggerHandler("beforeExecute") !== false)
{
if (toggle && ["ajaxbulk", "postcriteria", "ajax", "post"].indexOf(toggle) > -1)
{
if (!url)
url = button.attr("href");

if ($(this.$element).is("[data-enable-on-selection=true]")) {
$(this.$element).addClass("disabled");
}
};
var ids = {};

GriddlyButton.prototype = {
constructor: GriddlyButton,
if (griddly)
ids = griddly.griddly("getSelected");

// create and bind
create: function () {
var griddly = this.$element.closest("[data-role=griddly]");
var url = this.$element.data("url");
var toggle = this.$element.data("toggle");
var onclick = this.$element.data("onclick");
var confirmMessage = this.$element.data("confirm-message");
var enableOnSelection = this.$element.data("enable-on-selection");

$(this.$element).on("click", $.proxy(function (event) {
if ((typeof confirmMessage === "undefined" || confirm(confirmMessage))) {
if ($(this.$element).triggerHandler("beforeExecute") !== false) {
if (toggle && ["ajaxbulk", "postcriteria", "ajax", "post"].indexOf(toggle) > -1) {
if (!url)
url = $(event.currentTarget).attr("href");

var ids = {};
if (griddly)
ids = $(griddly).griddly("getSelected");

switch (toggle) {
case "ajaxbulk":
if (ids.length == 0 && enableOnSelection)
return;
return this.ajaxBulk(url, ids);

case "post":
if (ids.length == 0 && enableOnSelection)
return;
return this.post(url, ids);

case "postcriteria":
if (!griddly)
return;
return this.postCriteria(url, $(griddly).griddly("buildRequest"));

case "ajax":
if (ids.length == 0)
return;
return this.ajax(url, ids);
}
}
switch (toggle)
{
case "ajaxbulk":
if (ids.length == 0 && enableOnSelection)
return;

if (onclick) {
var f = window[onclick];
if ($.isFunction(f))
return f.call(this.$element);
throw "onclick must be a global function";
// we do not support eval cause it's insecure
}
return this.ajaxBulk(url, ids, button, griddly);

return true;
}
}
case "post":
if (ids.length == 0 && enableOnSelection)
return;

return false;
}, this));
},
return this.post(url, ids, button, griddly);

ajaxBulk: function (url, ids) {
$.ajax(url,
{
data: { ids: ids },
traditional: true,
type: "POST"
}).done($.proxy(function (data, status, xhr) {
// TODO: handle errors
// TODO: go back to first page?
var griddly = this.$element.closest("[data-role=griddly]");
griddly.griddly("refresh");
case "postcriteria":
if (!griddly)
return;

$(this.$element).triggerHandler("afterExecute", [data, status, xhr]);
}, this));
},
return this.postCriteria(url, griddly.griddly("buildRequest"));

post: function (url, ids) {
var inputs = "";
case "ajax":
if (ids.length == 0)
return;

var token = $("input[name^=__RequestVerificationToken]").first();
return this.ajax(url, ids, button, griddly);
}
}

if (token.length)
inputs += '<input type="hidden" name="' + token.attr("name") + '" value="' + token.val() + '" />';
if (onclick)
{
var f = window[onclick];

$.each(ids, function () {
inputs += "<input name=\"ids\" value=\"" + this + "\" />";
});
if ($.isFunction(f))
return f.call(button);

$("<form action=\"" + url + "\" method=\"post\">" + inputs + "</form>")
.appendTo("body").submit().remove();
throw "onclick must be a global function";
// we do not support eval cause it's insecure
}

return false;
},
return true;
}
}

postCriteria: function (url, request) {
var inputs = "";
return false;
}, GriddlyButton);

var token = $("input[name^=__RequestVerificationToken]").first();
GriddlyButton.ajaxBulk = function (url, ids, button, griddly)
{
$.ajax(url,
{
data: { ids: ids },
traditional: true,
type: "POST"
}).done($.proxy(function (data, status, xhr)
{
// TODO: handle errors
// TODO: go back to first page?
griddly.griddly("refresh");

if (token.length)
inputs += '<input type="hidden" name="' + token.attr("name") + '" value="' + token.val() + '" />';
button.triggerHandler("afterExecute", [data, status, xhr]);
}, this));
};

for (var key in request)
inputs += '<input name="' + key + '" value="' + request[key] + '" />';
GriddlyButton.post = function (url, ids, button, griddly)
{
var inputs = "";

$("<form action=\"" + url + "\" method=\"post\">" + inputs + "</form>")
.appendTo("body").submit().remove();
},
var token = $("input[name^=__RequestVerificationToken]").first();

ajax: function (url, ids) {
for (var i = 0; i < ids.length; i++) {
$.ajax(url,
{
data: { id: ids[i] },
type: "POST"
}).done($.proxy(function (data, status, xhr) {
// TODO: handle errors
// TODO: go back to first page?
var griddly = this.$element.closest("[data-role=griddly]");
griddly.griddly("refresh");

$(this.$element).triggerHandler("afterExecute", [data, status, xhr]);
}, this));
}
},
};
if (token.length)
inputs += '<input type="hidden" name="' + token.attr("name") + '" value="' + token.val() + '" />';

$.fn.griddlyButton = function (option, parameter) {
var value;
var args = arguments;
$.each(ids, function ()
{
inputs += "<input name=\"ids\" value=\"" + this + "\" />";
});

this.each(function () {
var data = $(this).data('griddly'),
options = typeof option == 'object' && option;
$("<form action=\"" + url + "\" method=\"post\">" + inputs + "</form>")
.appendTo("body").submit().remove();

// initialize griddly button
if (!data) {
var instanceOptions = $.extend({}, $.fn.griddlyButton.defaults, options);
return false;
};

$(this).data('griddly', (data = new GriddlyButton(this, instanceOptions)));
}
GriddlyButton.postCriteria = function (url, request, button, griddly)
{
var inputs = "";

// call griddly method
if (typeof option == 'string') {
value = data[option].apply(data, Array.prototype.slice.call(args, 1));
}
var token = $("input[name^=__RequestVerificationToken]").first();

});
if (token.length)
inputs += '<input type="hidden" name="' + token.attr("name") + '" value="' + token.val() + '" />';

if (value !== undefined)
return value;
else
return this;
for (var key in request)
inputs += '<input name="' + key + '" value="' + request[key] + '" />';

$("<form action=\"" + url + "\" method=\"post\">" + inputs + "</form>")
.appendTo("body").submit().remove();
};

$.fn.griddlyButton.defaults =
GriddlyButton.ajax = function (url, ids, button, griddly)
{
for (var i = 0; i < ids.length; i++)
{
$.ajax(url,
{
data: { id: ids[i] },
type: "POST"
}).done($.proxy(function (data, status, xhr)
{
// TODO: handle errors
// TODO: go back to first page?
griddly.griddly("refresh");

button.triggerHandler("afterExecute", [data, status, xhr]);
}, this));
}
};

$(function()
{
$("[data-role=griddly]").griddly();
$("[data-role=griddly-button]").griddlyButton();
$(document).on("click", "[data-role=griddly-button]", GriddlyButton.handleClick);

// patch stupid bootstrap js so it doesn't .empty() our inline filter dropdowns
// remove once bs fixes: https://github.com/twbs/bootstrap/pull/14244
Expand Down