Mercurial > hg > OKFNAnnotator
diff annotator_files/lib/plugin/permissions.js @ 4:6979313586cf
new version of annotator.
author | casties |
---|---|
date | Mon, 27 Aug 2012 19:05:38 +0200 |
parents | 6356e78ccf5c |
children |
line wrap: on
line diff
--- a/annotator_files/lib/plugin/permissions.js Thu Apr 05 19:37:27 2012 +0200 +++ b/annotator_files/lib/plugin/permissions.js Mon Aug 27 19:05:38 2012 +0200 @@ -1,6 +1,7 @@ +// Generated by CoffeeScript 1.3.3 var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __hasProp = Object.prototype.hasOwnProperty, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }; + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; Annotator.Plugin.Permissions = (function(_super) { @@ -23,10 +24,14 @@ var token, tokens, _i, _len; if (annotation.permissions) { tokens = annotation.permissions[action] || []; - if (tokens.length === 0) return true; + if (tokens.length === 0) { + return true; + } for (_i = 0, _len = tokens.length; _i < _len; _i++) { token = tokens[_i]; - if (this.userId(user) === token) return true; + if (this.userId(user) === token) { + return true; + } } return false; } else if (annotation.user) { @@ -45,10 +50,15 @@ function Permissions(element, options) { this._setAuthFromToken = __bind(this._setAuthFromToken, this); + this.updateViewer = __bind(this.updateViewer, this); + this.updateAnnotationPermissions = __bind(this.updateAnnotationPermissions, this); + this.updatePermissionsField = __bind(this.updatePermissionsField, this); - this.addFieldsToAnnotation = __bind(this.addFieldsToAnnotation, this); Permissions.__super__.constructor.apply(this, arguments); + + this.addFieldsToAnnotation = __bind(this.addFieldsToAnnotation, this); + Permissions.__super__.constructor.apply(this, arguments); if (this.options.user) { this.setUser(this.options.user); delete this.options.user; @@ -58,7 +68,9 @@ Permissions.prototype.pluginInit = function() { var createCallback, self, _this = this; - if (!Annotator.supported()) return; + if (!Annotator.supported()) { + return; + } self = this; createCallback = function(method, type) { return function(field, annotation) { @@ -94,11 +106,15 @@ isFiltered: function(input, user) { var keyword, _i, _len, _ref; user = _this.options.userString(user); - if (!(input && user)) return false; + if (!(input && user)) { + return false; + } _ref = input.split(/\s*/); for (_i = 0, _len = _ref.length; _i < _len; _i++) { keyword = _ref[_i]; - if (user.indexOf(keyword) === -1) return false; + if (user.indexOf(keyword) === -1) { + return false; + } } return true; } @@ -113,12 +129,16 @@ Permissions.prototype.addFieldsToAnnotation = function(annotation) { if (annotation) { annotation.permissions = this.options.permissions; - if (this.user) return annotation.user = this.user; + if (this.user) { + return annotation.user = this.user; + } } }; Permissions.prototype.authorize = function(action, annotation, user) { - if (user === void 0) user = this.user; + if (user === void 0) { + user = this.user; + } if (this.options.userAuthorize) { return this.options.userAuthorize.call(this.options, action, annotation, user); } else { @@ -130,7 +150,9 @@ var input; field = $(field).show(); input = field.find('input').removeAttr('disabled'); - if (!this.authorize('admin', annotation)) field.hide(); + if (!this.authorize('admin', annotation)) { + field.hide(); + } if (this.authorize(action, annotation || {}, null)) { return input.attr('checked', 'checked'); } else { @@ -140,7 +162,9 @@ Permissions.prototype.updateAnnotationPermissions = function(type, field, annotation) { var dataKey; - if (!annotation.permissions) annotation.permissions = this.options.permissions; + if (!annotation.permissions) { + annotation.permissions = this.options.permissions; + } dataKey = type + '-permissions'; if ($(field).find('input').is(':checked')) { return annotation.permissions[type] = []; @@ -159,8 +183,12 @@ } else { field.remove(); } - if (!this.authorize('update', annotation)) controls.hideEdit(); - if (!this.authorize('delete', annotation)) return controls.hideDelete(); + if (!this.authorize('update', annotation)) { + controls.hideEdit(); + } + if (!this.authorize('delete', annotation)) { + return controls.hideDelete(); + } }; Permissions.prototype._setAuthFromToken = function(token) {