| Conditions | 1 |
| Paths | 1536 |
| Total Lines | 460 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 | /* |
||
| 40 | initialize: function () { |
||
| 41 | var self = this; |
||
| 42 | var api = OCA.Circles.api; |
||
| 43 | |||
| 44 | var currCirclesType = ''; |
||
| 45 | var currentCircle = 0; |
||
| 46 | var currentCircleLevel = 0; |
||
| 47 | var lastSearchCircle = ''; |
||
| 48 | var lastSearchUser = ''; |
||
| 49 | |||
| 50 | |||
| 51 | $('#circles_new_type_definition div').fadeOut(0); |
||
| 52 | $('#circles_new_type_' + ($('#circles_new_type option:selected').val())).fadeIn(0); |
||
| 53 | |||
| 54 | $('#circles_new_type').hide(); |
||
| 55 | $('#circles_new_submit').hide(); |
||
| 56 | $('#circles_new_type_definition').hide(); |
||
| 57 | |||
| 58 | $('#circles_new_name').on('keyup', function (e) { |
||
|
|
|||
| 59 | currentCircle = 0; |
||
| 60 | currentCircleLevel = 0; |
||
| 61 | |||
| 62 | $('#app-navigation.circles').hide('slide', 800); |
||
| 63 | $('#circles_list div').removeClass('selected'); |
||
| 64 | $('#emptycontent').show(800); |
||
| 65 | $('#mainui').fadeOut(800); |
||
| 66 | |||
| 67 | if ($('#circles_new_name').val() != '') { |
||
| 68 | $('#circles_new_type').fadeIn(300); |
||
| 69 | $('#circles_new_submit').fadeIn(500); |
||
| 70 | $('#circles_new_type_definition').fadeIn(700); |
||
| 71 | } |
||
| 72 | else { |
||
| 73 | $('#circles_new_type').fadeOut(700); |
||
| 74 | $('#circles_new_submit').fadeOut(500); |
||
| 75 | $('#circles_new_type_definition').fadeOut(300); |
||
| 76 | } |
||
| 77 | }); |
||
| 78 | |||
| 79 | $('#circles_new_type').on('change', function () { |
||
| 80 | |||
| 81 | currentCircle = 0; |
||
| 82 | currentCircleLevel = 0; |
||
| 83 | |||
| 84 | $('#app-navigation.circles').hide('slide', 800); |
||
| 85 | $('#circles_list div').removeClass('selected'); |
||
| 86 | $('#emptycontent').show(800); |
||
| 87 | $('#mainui').fadeOut(800); |
||
| 88 | |||
| 89 | $('#circles_new_type_definition div').fadeOut(300); |
||
| 90 | $('#circles_new_type_' + ($('#circles_new_type option:selected').val())).fadeIn( |
||
| 91 | 300); |
||
| 92 | }); |
||
| 93 | |||
| 94 | $('#circles_new_submit').on('click', function () { |
||
| 95 | api.createCircle($('#circles_new_type').val(), $('#circles_new_name').val(), |
||
| 96 | self.createCircleResult); |
||
| 97 | }); |
||
| 98 | |||
| 99 | $('#circles_list div').on('click', function () { |
||
| 100 | self.displayCirclesList($(this).attr('circle-type')); |
||
| 101 | }); |
||
| 102 | |||
| 103 | $('#circles_search').on('input propertychange paste focus', function () { |
||
| 104 | if (lastSearchCircle == $(this).val().trim()) |
||
| 105 | return; |
||
| 106 | |||
| 107 | lastSearchCircle = $(this).val().trim(); |
||
| 108 | api.searchCircles(currCirclesType, $(this).val().trim(), |
||
| 109 | self.listCirclesResult); |
||
| 110 | }); |
||
| 111 | |||
| 112 | $('.icon-circles').css('background-image', |
||
| 113 | 'url(' + OC.imagePath('circles', 'colored') + ')'); |
||
| 114 | |||
| 115 | $('#joincircle').on('click', function () { |
||
| 116 | api.joinCircle(currentCircle, self.joinCircleResult); |
||
| 117 | }); |
||
| 118 | |||
| 119 | $('#leavecircle').on('click', function () { |
||
| 120 | api.leaveCircle(currentCircle, self.leaveCircleResult); |
||
| 121 | }); |
||
| 122 | |||
| 123 | $('#joincircle_acceptinvit').on('click', function () { |
||
| 124 | api.joinCircle(currentCircle, self.joinCircleResult); |
||
| 125 | }); |
||
| 126 | |||
| 127 | $('#joincircle_rejectinvit').on('click', function () { |
||
| 128 | api.leaveCircle(currentCircle, self.leaveCircleResult); |
||
| 129 | }); |
||
| 130 | |||
| 131 | $('#addmember').on('input propertychange paste focus', function () { |
||
| 132 | |||
| 133 | if (lastSearchUser == $(this).val().trim()) |
||
| 134 | return; |
||
| 135 | |||
| 136 | lastSearchUser = $(this).val().trim(); |
||
| 137 | |||
| 138 | $.get(OC.linkToOCS('apps/files_sharing/api/v1') + 'sharees', |
||
| 139 | { |
||
| 140 | format: 'json', |
||
| 141 | search: $(this).val().trim(), |
||
| 142 | perPage: 200, |
||
| 143 | itemType: 'principals' |
||
| 144 | }, self.searchMembersResult); |
||
| 145 | }).blur(function () { |
||
| 146 | $('#members_search_result').fadeOut(400); |
||
| 147 | }); |
||
| 148 | |||
| 149 | $('#members_search_result').hide(); |
||
| 150 | |||
| 151 | |||
| 152 | this.createCircleResult = function (result) { |
||
| 153 | var str = 'Circle'; |
||
| 154 | switch (result.type) { |
||
| 155 | case '1': |
||
| 156 | str = 'Personal circle'; |
||
| 157 | break; |
||
| 158 | case '2': |
||
| 159 | str = 'Hidden circle'; |
||
| 160 | break; |
||
| 161 | case '4': |
||
| 162 | str = 'Private circle'; |
||
| 163 | break; |
||
| 164 | case '8': |
||
| 165 | str = 'Public circle'; |
||
| 166 | break; |
||
| 167 | } |
||
| 168 | |||
| 169 | if (result.status == 1) { |
||
| 170 | OCA.notification.onSuccess(str + " '" + result.name + "' created"); |
||
| 171 | self.displayCirclesList(result.circle.type); |
||
| 172 | self.selectCircle(result.circle.id); |
||
| 173 | } |
||
| 174 | else |
||
| 175 | OCA.notification.onFail( |
||
| 176 | str + " '" + result.name + "' NOT created: " + |
||
| 177 | ((result.error) ? result.error : 'no error message')); |
||
| 178 | }; |
||
| 179 | |||
| 180 | |||
| 181 | // |
||
| 182 | // |
||
| 183 | // Circles List |
||
| 184 | this.displayCirclesList = function (type) { |
||
| 185 | |||
| 186 | self.currCirclesType = type; |
||
| 187 | self.lastSearchCircle = ''; |
||
| 188 | self.lastSearchUser = ''; |
||
| 189 | |||
| 190 | self.currentCircle = 0; |
||
| 191 | self.currentCircleLevel = 0; |
||
| 192 | |||
| 193 | $('#app-navigation.circles').show('slide', 800); |
||
| 194 | $('#emptycontent').show(800); |
||
| 195 | $('#mainui').fadeOut(800); |
||
| 196 | |||
| 197 | $('#circles_search').val(''); |
||
| 198 | $('#addmember').val(''); |
||
| 199 | |||
| 200 | $('#app-navigation.circles').addClass('selected'); |
||
| 201 | $('#circles_list div').removeClass('selected'); |
||
| 202 | |||
| 203 | $('#circles_list').children().each(function () { |
||
| 204 | if ($(this).attr('circle-type') == type.toLowerCase()) |
||
| 205 | $(this).addClass('selected'); |
||
| 206 | }); |
||
| 207 | |||
| 208 | $('#app-navigation.circles').children().each(function () { |
||
| 209 | if ($(this).attr('id') != 'circles_search') |
||
| 210 | $(this).remove(); |
||
| 211 | }); |
||
| 212 | api.listCircles(type, self.listCirclesResult); |
||
| 213 | }; |
||
| 214 | |||
| 215 | |||
| 216 | this.listCirclesResult = function (result) { |
||
| 217 | |||
| 218 | if (result.status < 1) { |
||
| 219 | OCA.notification.onFail( |
||
| 220 | 'Issue while retreiving the list of the Circles: ' + |
||
| 221 | ((result.error) ? result.error : 'no error message')); |
||
| 222 | return; |
||
| 223 | } |
||
| 224 | |||
| 225 | $('#app-navigation.circles').children().each(function () { |
||
| 226 | if ($(this).attr('id') != 'circles_search') |
||
| 227 | $(this).remove(); |
||
| 228 | }); |
||
| 229 | |||
| 230 | var data = result.data; |
||
| 231 | for (var i = 0; i < data.length; i++) { |
||
| 232 | |||
| 233 | // var curr = self.getCurrentCircleTemplate(data[i].id); |
||
| 234 | |||
| 235 | var tmpl = $('#tmpl_circle').html(); |
||
| 236 | |||
| 237 | tmpl = tmpl.replace(/%title%/, data[i].name); |
||
| 238 | tmpl = tmpl.replace(/%type%/, data[i].type); |
||
| 239 | tmpl = tmpl.replace(/%owner%/, data[i].owner.userid); |
||
| 240 | tmpl = tmpl.replace(/%status%/, data[i].user.status); |
||
| 241 | tmpl = tmpl.replace(/%level_string%/, data[i].user.level_string); |
||
| 242 | tmpl = tmpl.replace(/%count%/, data[i].count); |
||
| 243 | tmpl = tmpl.replace(/%creation%/, data[i].creation); |
||
| 244 | |||
| 245 | // if (curr == null) { |
||
| 246 | $('#app-navigation.circles').append( |
||
| 247 | '<div class="circle" circle-id="' + data[i].id + '">' + tmpl + '</div>'); |
||
| 248 | // } else { |
||
| 249 | // $(curr).html(tmpl); |
||
| 250 | // } |
||
| 251 | } |
||
| 252 | |||
| 253 | $('#app-navigation.circles').children('.circle').on('click', function () { |
||
| 254 | self.selectCircle($(this).attr('circle-id')); |
||
| 255 | }); |
||
| 256 | }; |
||
| 257 | |||
| 258 | |||
| 259 | this.selectCircle = function (circleid) { |
||
| 260 | self.lastSearchUser = ''; |
||
| 261 | $('#addmember').val(''); |
||
| 262 | |||
| 263 | api.detailsCircle(circleid, this.selectCircleResult); |
||
| 264 | }; |
||
| 265 | |||
| 266 | |||
| 267 | this.selectCircleResult = function (result) { |
||
| 268 | |||
| 269 | $('#mainui #memberslist .table').children('tr').each(function () { |
||
| 270 | if ($(this).attr('class') != 'header') |
||
| 271 | $(this).remove(); |
||
| 272 | }); |
||
| 273 | |||
| 274 | if (result.status < 1) { |
||
| 275 | OCA.notification.onFail( |
||
| 276 | 'Issue while retreiving the details of a circle: ' + |
||
| 277 | ((result.error) ? result.error : 'no error message')); |
||
| 278 | return; |
||
| 279 | } |
||
| 280 | |||
| 281 | $('#app-navigation.circles').children('.circle').each(function () { |
||
| 282 | if ($(this).attr('circle-id') == result.circle_id) |
||
| 283 | $(this).addClass('selected'); |
||
| 284 | else |
||
| 285 | $(this).removeClass('selected'); |
||
| 286 | }); |
||
| 287 | $('#emptycontent').hide(800); |
||
| 288 | $('#mainui').fadeIn(800); |
||
| 289 | self.currentCircle = result.circle_id; |
||
| 290 | self.currentCircleLevel = result.details.user.level; |
||
| 291 | |||
| 292 | if (result.details.user.level < 6) |
||
| 293 | $('#addmember').hide(); |
||
| 294 | else |
||
| 295 | $('#addmember').show(); |
||
| 296 | |||
| 297 | $('#joincircle_acceptinvit').hide(); |
||
| 298 | $('#joincircle_rejectinvit').hide(); |
||
| 299 | $('#joincircle_request').hide(); |
||
| 300 | $('#joincircle_invit').hide(); |
||
| 301 | |||
| 302 | if (result.details.user.level == 9) { |
||
| 303 | $('#joincircle').hide(); |
||
| 304 | $('#leavecircle').hide(); |
||
| 305 | } |
||
| 306 | else if (result.details.user.level >= 1) { |
||
| 307 | $('#joincircle').hide(); |
||
| 308 | $('#leavecircle').show(); |
||
| 309 | } else { |
||
| 310 | if (result.details.user.status == 'Invited') { |
||
| 311 | $('#joincircle_invit').show(); |
||
| 312 | $('#joincircle_acceptinvit').show(); |
||
| 313 | $('#joincircle_rejectinvit').show(); |
||
| 314 | $('#joincircle').hide(); |
||
| 315 | $('#leavecircle').hide(); |
||
| 316 | } |
||
| 317 | else if (result.details.user.status == 'Requesting') { |
||
| 318 | $('#joincircle_request').show(); |
||
| 319 | $('#joincircle').hide(); |
||
| 320 | $('#leavecircle').show(); |
||
| 321 | } |
||
| 322 | else { |
||
| 323 | $('#joincircle').show(); |
||
| 324 | $('#leavecircle').hide(); |
||
| 325 | } |
||
| 326 | } |
||
| 327 | |||
| 328 | self.displayMembers(result.details.members); |
||
| 329 | }; |
||
| 330 | |||
| 331 | |||
| 332 | this.searchMembersResult = function (response) { |
||
| 333 | |||
| 334 | if (response == null || |
||
| 335 | (response.ocs.data.users == 0 && response.ocs.data.exact.users == 0)) |
||
| 336 | $('#members_search_result').fadeOut(300); |
||
| 337 | |||
| 338 | else { |
||
| 339 | var currSearch = $('#addmember').val().trim(); |
||
| 340 | $('#members_search_result').children().remove(); |
||
| 341 | |||
| 342 | $.each(response.ocs.data.exact.users, function (index, value) { |
||
| 343 | $('#members_search_result').append( |
||
| 344 | '<div class="members_search exact" searchresult="' + |
||
| 345 | value.value.shareWith + '">' + value.label + ' (' + |
||
| 346 | value.value.shareWith + ')</div>'); |
||
| 347 | }); |
||
| 348 | |||
| 349 | $.each(response.ocs.data.users, function (index, value) { |
||
| 350 | var line = value.label + ' (' + value.value.shareWith + ')'; |
||
| 351 | if (currSearch.length > 0) line = |
||
| 352 | line.replace(new RegExp('(' + currSearch + ')', 'gi'), '<b>$1</b>'); |
||
| 353 | |||
| 354 | $('#members_search_result').append( |
||
| 355 | '<div class="members_search" searchresult="' + value.value.shareWith + |
||
| 356 | '">' + line + '</div>'); |
||
| 357 | }); |
||
| 358 | |||
| 359 | $('#members_search_result').children().first().css('border-top-width', '0px'); |
||
| 360 | |||
| 361 | $('.members_search').on('click', function () { |
||
| 362 | api.addMember(self.currentCircle, $(this).attr('searchresult'), |
||
| 363 | self.addMemberResult); |
||
| 364 | }); |
||
| 365 | $('#members_search_result').fadeIn(300); |
||
| 366 | } |
||
| 367 | |||
| 368 | }; |
||
| 369 | |||
| 370 | |||
| 371 | this.addMemberResult = function (result) { |
||
| 372 | |||
| 373 | if (result.status == 1) { |
||
| 374 | OCA.notification.onSuccess( |
||
| 375 | "Member '" + result.name + "' successfully added to the circle"); |
||
| 376 | |||
| 377 | self.displayMembers(result.members); |
||
| 378 | } |
||
| 379 | else |
||
| 380 | OCA.notification.onFail( |
||
| 381 | "Member '" + result.name + "' NOT added to the circle: " + |
||
| 382 | ((result.error) ? result.error : 'no error message')); |
||
| 383 | |||
| 384 | }; |
||
| 385 | |||
| 386 | |||
| 387 | this.displayMembers = function (members) { |
||
| 388 | |||
| 389 | $('#mainui #memberslist .table').children('tr').each(function () { |
||
| 390 | if ($(this).attr('class') != 'header') |
||
| 391 | $(this).remove(); |
||
| 392 | }); |
||
| 393 | |||
| 394 | if (members == null) { |
||
| 395 | $('#mainui #memberslist .table').hide(200); |
||
| 396 | return; |
||
| 397 | } |
||
| 398 | |||
| 399 | $('#mainui #memberslist .table').show(200); |
||
| 400 | for (var i = 0; i < members.length; i++) { |
||
| 401 | |||
| 402 | var tmpl = $('#tmpl_member').html(); |
||
| 403 | |||
| 404 | tmpl = tmpl.replace(/%username%/g, members[i].userid); |
||
| 405 | tmpl = tmpl.replace(/%level%/g, members[i].level); |
||
| 406 | tmpl = tmpl.replace(/%levelstring%/g, members[i].level_string); |
||
| 407 | tmpl = tmpl.replace(/%status%/, members[i].status); |
||
| 408 | tmpl = tmpl.replace(/%joined%/, members[i].joined); |
||
| 409 | tmpl = tmpl.replace(/%note%/, |
||
| 410 | ((members[i].note) ? members[i].note : '')); |
||
| 411 | |||
| 412 | $('#mainui #memberslist .table').append(tmpl); |
||
| 413 | } |
||
| 414 | |||
| 415 | $('#mainui #memberslist .table').children().each(function () { |
||
| 416 | if ($(this).attr('member-level') == '9' || self.currentCircleLevel < 6) |
||
| 417 | $(this).children('.delete').hide(0); |
||
| 418 | }); |
||
| 419 | |||
| 420 | $('#mainui #memberslist .table .delete').on('click', function () { |
||
| 421 | var member = $(this).parent().attr('member-id'); |
||
| 422 | api.removeMember(self.currentCircle, member, self.removeMemberResult); |
||
| 423 | }); |
||
| 424 | }; |
||
| 425 | |||
| 426 | |||
| 427 | this.removeMemberResult = function (result) { |
||
| 428 | if (result.status == 1) { |
||
| 429 | |||
| 430 | $('#mainui #memberslist .table').children().each(function () { |
||
| 431 | if ($(this).attr('member-id') == result.name) |
||
| 432 | $(this).hide(300); |
||
| 433 | }); |
||
| 434 | |||
| 435 | OCA.notification.onSuccess( |
||
| 436 | "Member '" + result.name + "' successfully removed from the circle"); |
||
| 437 | } |
||
| 438 | else |
||
| 439 | OCA.notification.onFail( |
||
| 440 | "Member '" + result.name + "' NOT removed from the circle: " + |
||
| 441 | ((result.error) ? result.error : 'no error message')); |
||
| 442 | |||
| 443 | }; |
||
| 444 | |||
| 445 | |||
| 446 | this.joinCircleResult = function (result) { |
||
| 447 | if (result.status == 1) { |
||
| 448 | |||
| 449 | $('#mainui #memberslist .table').children().each(function () { |
||
| 450 | if ($(this).attr('member-id') == result.name) |
||
| 451 | $(this).hide(300); |
||
| 452 | }); |
||
| 453 | |||
| 454 | if (result.member.level == 1) |
||
| 455 | OCA.notification.onSuccess( |
||
| 456 | "You have successfully joined this circle"); |
||
| 457 | else |
||
| 458 | OCA.notification.onSuccess( |
||
| 459 | "You have requested an invitation to join this circle"); |
||
| 460 | self.selectCircle(result.circle_id); |
||
| 461 | |||
| 462 | } |
||
| 463 | else |
||
| 464 | OCA.notification.onFail( |
||
| 465 | "Cannot join this circle: " + |
||
| 466 | ((result.error) ? result.error : 'no error message')); |
||
| 467 | }; |
||
| 468 | |||
| 469 | this.leaveCircleResult = function (result) { |
||
| 470 | if (result.status == 1) { |
||
| 471 | |||
| 472 | $('#mainui #memberslist .table').children().each(function () { |
||
| 473 | if ($(this).attr('member-id') == result.name) |
||
| 474 | $(this).hide(300); |
||
| 475 | }); |
||
| 476 | |||
| 477 | OCA.notification.onSuccess( |
||
| 478 | "You have successfully left this circle"); |
||
| 479 | |||
| 480 | self.selectCircle(result.circle_id); |
||
| 481 | } |
||
| 482 | else |
||
| 483 | OCA.notification.onFail( |
||
| 484 | "Cannot leave this circle: " + |
||
| 485 | ((result.error) ? result.error : 'no error message')); |
||
| 486 | }; |
||
| 487 | |||
| 488 | // getCurrentCircleTemplate: function (id) { |
||
| 489 | // |
||
| 490 | // currdiv = null; |
||
| 491 | // $('#app-navigation.circles').children().each(function () { |
||
| 492 | // if ($(this).attr('circle-id') == id) { |
||
| 493 | // currdiv = $(this); |
||
| 494 | // return false; |
||
| 495 | // } |
||
| 496 | // }); |
||
| 497 | // return currdiv; |
||
| 498 | // } |
||
| 499 | } |
||
| 500 | }; |
||
| 540 |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.