| Conditions | 1 |
| Paths | 2 |
| Total Lines | 204 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /* |
||
| 29 | (function () { |
||
| 30 | |||
| 31 | |||
| 32 | /** |
||
| 33 | * @constructs Circles |
||
| 34 | */ |
||
| 35 | var Circles = function () { |
||
| 36 | this.initialize(); |
||
| 37 | }; |
||
| 38 | |||
| 39 | Circles.prototype = { |
||
| 40 | |||
| 41 | |||
| 42 | initialize: function () { |
||
| 43 | |||
| 44 | var self = this; |
||
| 45 | |||
| 46 | this.createCircle = function (type, name, callback) { |
||
| 47 | |||
| 48 | var result = {status: -1}; |
||
| 49 | $.ajax({ |
||
| 50 | method: 'PUT', |
||
| 51 | url: OC.generateUrl('/apps/circles/circles'), |
||
| 52 | data: { |
||
| 53 | type: type, |
||
| 54 | name: name |
||
| 55 | } |
||
| 56 | }).done(function (res) { |
||
| 57 | self.onCallback(callback, res); |
||
| 58 | }).fail(function () { |
||
| 59 | self.onCallback(callback, result); |
||
| 60 | }); |
||
| 61 | }; |
||
| 62 | |||
| 63 | |||
| 64 | // this.listCircles = function (type, callback) { |
||
| 65 | // var result = {status: -1}; |
||
| 66 | // $.ajax({ |
||
| 67 | // method: 'GET', |
||
| 68 | // url: OC.generateUrl(OC.linkTo('circles', 'circles')), |
||
| 69 | // data: { |
||
| 70 | // type: type |
||
| 71 | // } |
||
| 72 | // }).done(function (res) { |
||
| 73 | // self.onCallback(callback, res); |
||
| 74 | // }).fail(function () { |
||
| 75 | // self.onCallback(callback, result); |
||
| 76 | // }); |
||
| 77 | // }; |
||
| 78 | |||
| 79 | |||
| 80 | this.searchCircles = function (type, name, level, callback) { |
||
| 81 | var result = {status: -1}; |
||
| 82 | $.ajax({ |
||
| 83 | method: 'GET', |
||
| 84 | url: OC.generateUrl('/apps/circles/circles'), |
||
| 85 | data: { |
||
| 86 | type: type, |
||
| 87 | name: name, |
||
| 88 | level: level |
||
| 89 | } |
||
| 90 | }).done(function (res) { |
||
| 91 | self.onCallback(callback, res); |
||
| 92 | }).fail(function () { |
||
| 93 | self.onCallback(callback, result); |
||
| 94 | }); |
||
| 95 | }; |
||
| 96 | |||
| 97 | |||
| 98 | this.detailsCircle = function (circleId, callback) { |
||
| 99 | var result = {status: -1}; |
||
| 100 | $.ajax({ |
||
| 101 | method: 'GET', |
||
| 102 | url: OC.generateUrl('/apps/circles/circles/' + circleId) |
||
| 103 | }).done(function (res) { |
||
| 104 | self.onCallback(callback, res); |
||
| 105 | }).fail(function () { |
||
| 106 | self.onCallback(callback, result); |
||
| 107 | }); |
||
| 108 | }; |
||
| 109 | |||
| 110 | |||
| 111 | this.addMember = function (circleId, member, callback) { |
||
| 112 | var result = {status: -1}; |
||
| 113 | $.ajax({ |
||
| 114 | method: 'PUT', |
||
| 115 | url: OC.generateUrl('/apps/circles/circles/' + circleId + '/members'), |
||
| 116 | data: { |
||
| 117 | name: member |
||
| 118 | } |
||
| 119 | }).done(function (res) { |
||
| 120 | self.onCallback(callback, res); |
||
| 121 | }).fail(function () { |
||
| 122 | self.onCallback(callback, result); |
||
| 123 | }); |
||
| 124 | }; |
||
| 125 | |||
| 126 | |||
| 127 | this.removeMember = function (circleId, member, callback) { |
||
| 128 | var result = {status: -1}; |
||
| 129 | $.ajax({ |
||
| 130 | method: 'DELETE', |
||
| 131 | url: OC.generateUrl('/apps/circles/circles/' + circleId + '/members'), |
||
| 132 | data: { |
||
| 133 | member: member |
||
| 134 | } |
||
| 135 | }).done(function (res) { |
||
| 136 | self.onCallback(callback, res); |
||
| 137 | }).fail(function () { |
||
| 138 | self.onCallback(callback, result); |
||
| 139 | }); |
||
| 140 | }; |
||
| 141 | |||
| 142 | |||
| 143 | this.joinCircle = function (circleId, callback) { |
||
| 144 | var result = {status: -1}; |
||
| 145 | $.ajax({ |
||
| 146 | method: 'GET', |
||
| 147 | url: OC.generateUrl('/apps/circles/circles/' + circleId + '/join'), |
||
| 148 | data: {} |
||
| 149 | }).done(function (res) { |
||
| 150 | self.onCallback(callback, res); |
||
| 151 | }).fail(function () { |
||
| 152 | self.onCallback(callback, result); |
||
| 153 | }); |
||
| 154 | }; |
||
| 155 | |||
| 156 | |||
| 157 | this.leaveCircle = function (circleId, callback) { |
||
| 158 | var result = {status: -1}; |
||
| 159 | $.ajax({ |
||
| 160 | method: 'GET', |
||
| 161 | url: OC.generateUrl('/apps/circles/circles/' + circleId + '/leave'), |
||
| 162 | data: {} |
||
| 163 | }).done(function (res) { |
||
| 164 | self.onCallback(callback, res); |
||
| 165 | }).fail(function () { |
||
| 166 | self.onCallback(callback, result); |
||
| 167 | }); |
||
| 168 | }; |
||
| 169 | |||
| 170 | |||
| 171 | this.destroyCircle = function (circleId, callback) { |
||
| 172 | var result = {status: -1}; |
||
| 173 | $.ajax({ |
||
| 174 | method: 'DELETE', |
||
| 175 | url: OC.generateUrl('/apps/circles/circles/' + circleId), |
||
| 176 | data: {} |
||
| 177 | }).done(function (res) { |
||
| 178 | self.onCallback(callback, res); |
||
| 179 | }).fail(function () { |
||
| 180 | self.onCallback(callback, result); |
||
| 181 | }); |
||
| 182 | }; |
||
| 183 | |||
| 184 | |||
| 185 | this.shareToCircle = function (circleId, source, type, item, callback) { |
||
| 186 | var result = {status: -1}; |
||
| 187 | $.ajax({ |
||
| 188 | method: 'PUT', |
||
| 189 | url: OC.generateUrl('/apps/circles/circles/' + circleId + '/share'), |
||
| 190 | data: { |
||
| 191 | source: source, |
||
| 192 | type: type, |
||
| 193 | item: item |
||
| 194 | } |
||
| 195 | }).done(function (res) { |
||
| 196 | self.onCallback(callback, res); |
||
| 197 | }).fail(function () { |
||
| 198 | self.onCallback(callback, result); |
||
| 199 | }); |
||
| 200 | }; |
||
| 201 | |||
| 202 | |||
| 203 | this.linkCircle = function (circleId, remote, callback) { |
||
| 204 | var result = {status: -1}; |
||
| 205 | $.ajax({ |
||
| 206 | method: 'PUT', |
||
| 207 | url: OC.generateUrl('/apps/circles/circles/' + circleId + '/link'), |
||
| 208 | data: { |
||
| 209 | remote: remote |
||
| 210 | } |
||
| 211 | }).done(function (res) { |
||
| 212 | self.onCallback(callback, res); |
||
| 213 | }).fail(function () { |
||
| 214 | self.onCallback(callback, result); |
||
| 215 | }); |
||
| 216 | }; |
||
| 217 | |||
| 218 | |||
| 219 | this.onCallback = function (callback, result) { |
||
| 220 | if (callback && (typeof callback === "function")) { |
||
| 221 | callback(result); |
||
| 222 | } |
||
| 223 | }; |
||
| 224 | |||
| 225 | } |
||
| 226 | |||
| 227 | }; |
||
| 228 | |||
| 229 | OCA.Circles = Circles; |
||
| 230 | OCA.Circles.api = new Circles(); |
||
| 231 | |||
| 232 | })(); |
||
| 233 | |||
| 235 |