Merge a3c54e4477
into 454c0b2e7e
This commit is contained in:
commit
a52eaa9b47
|
@ -195,6 +195,8 @@ class Wrapper
|
|||
@actionOpenWindow(message.params)
|
||||
else if cmd == "wrapperPermissionAdd"
|
||||
@actionPermissionAdd(message)
|
||||
else if cmd == "wrapperPermissionRemove"
|
||||
@actionPermissionRemove(message)
|
||||
else if cmd == "wrapperRequestFullscreen"
|
||||
@actionRequestFullscreen()
|
||||
else if cmd == "wrapperWebNotification"
|
||||
|
@ -283,14 +285,37 @@ class Wrapper
|
|||
|
||||
actionPermissionAdd: (message) ->
|
||||
permission = message.params
|
||||
if Array.isArray(permission) && permission.length > 1
|
||||
@sendInner {"cmd": "response", "to": message.id, "result": {"error": "Can only grant one permission at the time"}}
|
||||
return false
|
||||
if Array.isArray(permission) && permission.length == 1
|
||||
permission = permission[0]
|
||||
$.when(@event_site_info).done =>
|
||||
if permission in @site_info.settings.permissions
|
||||
@notifications.add "notification-#{message.id}", "info", "Permission already granted.", 4000
|
||||
return false
|
||||
@ws.cmd "permissionDetails", permission, (permission_details) =>
|
||||
@displayConfirm "This site requests permission:" + " <b>#{@toHtmlSafe(permission)}</b>" + "<br><small style='color: #4F4F4F'>#{permission_details}</small>", "Grant", =>
|
||||
@ws.cmd "permissionAdd", permission, (res) =>
|
||||
@sendInner {"cmd": "response", "to": message.id, "result": res}
|
||||
|
||||
actionPermissionRemove: (message) ->
|
||||
permission = message.params
|
||||
if Array.isArray(permission) && permission.length > 1
|
||||
@sendInner {"cmd": "response", "to": message.id, "result": {"error": "Can only remove one permission at the time"}}
|
||||
return false
|
||||
if Array.isArray(permission) && permission.length == 1
|
||||
permission = permission[0]
|
||||
$.when(@event_site_info).done =>
|
||||
if permission not in @site_info.settings.permissions
|
||||
@notifications.add "notification-#{message.id}", "info", "Permission already removed.", 4000
|
||||
return false
|
||||
@ws.cmd "permissionDetails", permission, (permission_details) =>
|
||||
@displayConfirm "This site wants to remove permission:" + " <b>#{@toHtmlSafe(permission)}</b>" + "<br><small style='color: #4F4F4F'>#{permission_details}</small>", "Remove", =>
|
||||
@ws.cmd "permissionRemove", permission, (res) =>
|
||||
@sendInner {"cmd": "response", "to": message.id, "result": res}
|
||||
|
||||
|
||||
actionNotification: (message) ->
|
||||
message.params = @toHtmlSafe(message.params) # Escape html
|
||||
body = $("<span class='message'>"+message.params[1]+"</span>")
|
||||
|
@ -711,4 +736,3 @@ else
|
|||
ws_url = proto.ws + ":" + origin.replace(proto.http+":", "") + "/ZeroNet-Internal/Websocket?wrapper_key=" + window.wrapper_key
|
||||
|
||||
window.wrapper = new Wrapper(ws_url)
|
||||
|
||||
|
|
|
@ -1191,6 +1191,8 @@ $.extend( $.easing,
|
|||
return this.actionOpenWindow(message.params);
|
||||
} else if (cmd === "wrapperPermissionAdd") {
|
||||
return this.actionPermissionAdd(message);
|
||||
} else if (cmd === "wrapperPermissionRemove") {
|
||||
return this.actionPermissionRemove(message);
|
||||
} else if (cmd === "wrapperRequestFullscreen") {
|
||||
return this.actionRequestFullscreen();
|
||||
} else if (cmd === "wrapperWebNotification") {
|
||||
|
@ -1346,9 +1348,23 @@ $.extend( $.easing,
|
|||
Wrapper.prototype.actionPermissionAdd = function(message) {
|
||||
var permission;
|
||||
permission = message.params;
|
||||
if (Array.isArray(permission) && permission.length > 1) {
|
||||
this.sendInner({
|
||||
"cmd": "response",
|
||||
"to": message.id,
|
||||
"result": {
|
||||
"error": "Can only grant one permission at the time"
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
if (Array.isArray(permission) && permission.length === 1) {
|
||||
permission = permission[0];
|
||||
}
|
||||
return $.when(this.event_site_info).done((function(_this) {
|
||||
return function() {
|
||||
if (indexOf.call(_this.site_info.settings.permissions, permission) >= 0) {
|
||||
_this.notifications.add("notification-" + message.id, "info", "Permission already granted.", 4000);
|
||||
return false;
|
||||
}
|
||||
return _this.ws.cmd("permissionDetails", permission, function(permission_details) {
|
||||
|
@ -1366,6 +1382,43 @@ $.extend( $.easing,
|
|||
})(this));
|
||||
};
|
||||
|
||||
Wrapper.prototype.actionPermissionRemove = function(message) {
|
||||
var permission;
|
||||
permission = message.params;
|
||||
if (Array.isArray(permission) && permission.length > 1) {
|
||||
this.sendInner({
|
||||
"cmd": "response",
|
||||
"to": message.id,
|
||||
"result": {
|
||||
"error": "Can only remove one permission at the time"
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
if (Array.isArray(permission) && permission.length === 1) {
|
||||
permission = permission[0];
|
||||
}
|
||||
return $.when(this.event_site_info).done((function(_this) {
|
||||
return function() {
|
||||
if (indexOf.call(_this.site_info.settings.permissions, permission) < 0) {
|
||||
_this.notifications.add("notification-" + message.id, "info", "Permission already removed.", 4000);
|
||||
return false;
|
||||
}
|
||||
return _this.ws.cmd("permissionDetails", permission, function(permission_details) {
|
||||
return _this.displayConfirm("This site wants to remove permission:" + (" <b>" + (_this.toHtmlSafe(permission)) + "</b>") + ("<br><small style='color: #4F4F4F'>" + permission_details + "</small>"), "Remove", function() {
|
||||
return _this.ws.cmd("permissionRemove", permission, function(res) {
|
||||
return _this.sendInner({
|
||||
"cmd": "response",
|
||||
"to": message.id,
|
||||
"result": res
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
})(this));
|
||||
};
|
||||
|
||||
Wrapper.prototype.actionNotification = function(message) {
|
||||
var body;
|
||||
message.params = this.toHtmlSafe(message.params);
|
||||
|
|
Loading…
Reference in New Issue