From 4f2e2601138e0c2b95aed03a55ee5df3293cc86c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Barrag=C3=A1n=20Merino?= Date: Tue, 29 Jul 2014 00:14:38 +0200 Subject: [PATCH] Create AttachmentsMixin Controller --- app/coffee/modules/controllerMixins.coffee | 41 +++++++++++++++++++--- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/app/coffee/modules/controllerMixins.coffee b/app/coffee/modules/controllerMixins.coffee index b7d1af25..ab62c0c6 100644 --- a/app/coffee/modules/controllerMixins.coffee +++ b/app/coffee/modules/controllerMixins.coffee @@ -27,6 +27,10 @@ trim = @.taiga.trim toString = @.taiga.toString +############################################################################# +## Page Mixin +############################################################################# + class PageMixin loadUsersAndRoles: -> promise = @q.all([ @@ -48,8 +52,13 @@ class PageMixin return results +taiga.PageMixin = PageMixin -# This mixin requires @location and @scope + +############################################################################# +## Filters Mixin +############################################################################# +# This mixin requires @location ($tgLocation) and @scope class FiltersMixin selectFilter: (name, value, load=false) -> @@ -88,7 +97,31 @@ class FiltersMixin location = if load then @location else @location.noreload(@scope) location.search(name, value) - -taiga = @.taiga -taiga.PageMixin = PageMixin taiga.FiltersMixin = FiltersMixin + + +############################################################################# +## Attachments Mixin +############################################################################# +# This mixin requires @rs ($tgResources), @scope and @log ($tgLog) +# The mixin required @..attachmentsUrlName (p.e. 'issues/attachments',see resources.coffee) + +class AttachmentsMixin + loadAttachments: (objectId) -> + if not @.attachmentsUrlName + return @log.error "AttachmentsMixin: @.attachmentsUrlName is required" + + @scope.attachmentsCount = 0 + @scope.activeAttachmentsCount = 0 + @scope.deprecatedAttachmentsCount = 0 + + return @rs.attachments.list(@.attachmentsUrlName, objectId).then (attachments) => + @scope.attachments = _.sortBy(attachments, "order") + @scope.attachmentsCount = @scope.attachments.length + @scope.activeAttachments = _.filter(@scope.attachments, is_deprecated: false) + @scope.activeAttachmentsCount = @scope.activeAttachments.length + @scope.deprecatedAttachments = _.filter(@scope.attachments, is_deprecated: true) + @scope.deprecatedAttachmentsCount = @scope.deprecatedAttachments.length + return attachments + +taiga.AttachmentsMixin = AttachmentsMixin