Changeset 4:6979313586cf in OKFNAnnotator (for Zope) for annotator_files/lib/plugin/permissions.js
- Timestamp:
- Aug 27, 2012, 5:05:38 PM (12 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
annotator_files/lib/plugin/permissions.js
r3 r4 1 // Generated by CoffeeScript 1.3.3 1 2 var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 2 __hasProp = Object.prototype.hasOwnProperty,3 __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; };3 __hasProp = {}.hasOwnProperty, 4 __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; }; 4 5 5 6 Annotator.Plugin.Permissions = (function(_super) { … … 24 25 if (annotation.permissions) { 25 26 tokens = annotation.permissions[action] || []; 26 if (tokens.length === 0) return true; 27 if (tokens.length === 0) { 28 return true; 29 } 27 30 for (_i = 0, _len = tokens.length; _i < _len; _i++) { 28 31 token = tokens[_i]; 29 if (this.userId(user) === token) return true; 32 if (this.userId(user) === token) { 33 return true; 34 } 30 35 } 31 36 return false; … … 46 51 function Permissions(element, options) { 47 52 this._setAuthFromToken = __bind(this._setAuthFromToken, this); 53 48 54 this.updateViewer = __bind(this.updateViewer, this); 55 49 56 this.updateAnnotationPermissions = __bind(this.updateAnnotationPermissions, this); 57 50 58 this.updatePermissionsField = __bind(this.updatePermissionsField, this); 51 this.addFieldsToAnnotation = __bind(this.addFieldsToAnnotation, this); Permissions.__super__.constructor.apply(this, arguments); 59 60 this.addFieldsToAnnotation = __bind(this.addFieldsToAnnotation, this); 61 Permissions.__super__.constructor.apply(this, arguments); 52 62 if (this.options.user) { 53 63 this.setUser(this.options.user); … … 59 69 var createCallback, self, 60 70 _this = this; 61 if (!Annotator.supported()) return; 71 if (!Annotator.supported()) { 72 return; 73 } 62 74 self = this; 63 75 createCallback = function(method, type) { … … 95 107 var keyword, _i, _len, _ref; 96 108 user = _this.options.userString(user); 97 if (!(input && user)) return false; 109 if (!(input && user)) { 110 return false; 111 } 98 112 _ref = input.split(/\s*/); 99 113 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 100 114 keyword = _ref[_i]; 101 if (user.indexOf(keyword) === -1) return false; 115 if (user.indexOf(keyword) === -1) { 116 return false; 117 } 102 118 } 103 119 return true; … … 114 130 if (annotation) { 115 131 annotation.permissions = this.options.permissions; 116 if (this.user) return annotation.user = this.user; 132 if (this.user) { 133 return annotation.user = this.user; 134 } 117 135 } 118 136 }; 119 137 120 138 Permissions.prototype.authorize = function(action, annotation, user) { 121 if (user === void 0) user = this.user; 139 if (user === void 0) { 140 user = this.user; 141 } 122 142 if (this.options.userAuthorize) { 123 143 return this.options.userAuthorize.call(this.options, action, annotation, user); … … 131 151 field = $(field).show(); 132 152 input = field.find('input').removeAttr('disabled'); 133 if (!this.authorize('admin', annotation)) field.hide(); 153 if (!this.authorize('admin', annotation)) { 154 field.hide(); 155 } 134 156 if (this.authorize(action, annotation || {}, null)) { 135 157 return input.attr('checked', 'checked'); … … 141 163 Permissions.prototype.updateAnnotationPermissions = function(type, field, annotation) { 142 164 var dataKey; 143 if (!annotation.permissions) annotation.permissions = this.options.permissions; 165 if (!annotation.permissions) { 166 annotation.permissions = this.options.permissions; 167 } 144 168 dataKey = type + '-permissions'; 145 169 if ($(field).find('input').is(':checked')) { … … 160 184 field.remove(); 161 185 } 162 if (!this.authorize('update', annotation)) controls.hideEdit(); 163 if (!this.authorize('delete', annotation)) return controls.hideDelete(); 186 if (!this.authorize('update', annotation)) { 187 controls.hideEdit(); 188 } 189 if (!this.authorize('delete', annotation)) { 190 return controls.hideDelete(); 191 } 164 192 }; 165 193
Note: See TracChangeset
for help on using the changeset viewer.