<commit_before>###
# Copyright (C) 2014 <NAME> <<EMAIL>>
# Copyright (C) 2014 <NAME> <<EMAIL>>
# Copyright (C) 2014 <NAME> <<EMAIL>>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# File: modules/backlog/sortable.coffee
###

taiga = @.taiga

mixOf = @.taiga.mixOf
toggleText = @.taiga.toggleText
scopeDefer = @.taiga.scopeDefer
bindOnce = @.taiga.bindOnce
groupBy = @.taiga.groupBy

module = angular.module("taigaBacklog")


#############################################################################
## Sortable Directive
#############################################################################

deleteElement = (el) ->
    el.scope().$destroy()
    el.off()
    el.remove()

BacklogSortableDirective = ($repo, $rs, $rootscope) ->
    # Notes about jquery bug:
    # http://stackoverflow.com/questions/5791886/jquery-draggable-shows-
    # helper-in-wrong-place-when-scrolled-down-page

    link = ($scope, $el, $attrs) ->
        bindOnce $scope, "project", (project) ->
            # If the user has not enough permissions we don't enable the sortable
            if not (project.my_permissions.indexOf("modify_us") > -1)
                return

            $el.sortable({
                connectWith: ".sprint-table"
                containment: ".wrapper"
                dropOnEmpty: true
                placeholder: "row us-item-row us-item-drag sortable-placeholder"
                # With scroll activated, it has strange behavior
                # with not full screen browser window.
                scroll: false
                # A consequence of length of backlog user story item
                # the default tolerance ("intersection") not works properly.
                tolerance: "pointer"
                # Revert on backlog is disabled bacause it works bad. Something
                # on the current taiga backlog structure or style makes jquery ui
                # works unexpectly (in some circumstances calculates wrong
                # position for revert).
                revert: false
            })

            $el.on "sortreceive", (event, ui) ->
                itemUs = ui.item.scope().us
                itemIndex = ui.item.index()

                deleteElement(ui.item)
                $scope.$emit("sprint:us:move", itemUs, itemIndex, null)
                ui.item.find('a').removeClass('noclick')

            $el.on "sortstop", (event, ui) ->
                # When parent not exists, do nothing
                if ui.item.parent().length == 0
                    return<commit_msg>Fix bug #911: Force the cursor at the right of the sortable<commit_after>###
# Copyright (C) 2014 <NAME> <<EMAIL>>
# Copyright (C) 2014 <NAME> <<EMAIL>>
# Copyright (C) 2014 <NAME> <<EMAIL>>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# File: modules/backlog/sortable.coffee
###

taiga = @.taiga

mixOf = @.taiga.mixOf
toggleText = @.taiga.toggleText
scopeDefer = @.taiga.scopeDefer
bindOnce = @.taiga.bindOnce
groupBy = @.taiga.groupBy

module = angular.module("taigaBacklog")


#############################################################################
## Sortable Directive
#############################################################################

deleteElement = (el) ->
    el.scope().$destroy()
    el.off()
    el.remove()

BacklogSortableDirective = ($repo, $rs, $rootscope) ->
    # Notes about jquery bug:
    # http://stackoverflow.com/questions/5791886/jquery-draggable-shows-
    # helper-in-wrong-place-when-scrolled-down-page

    link = ($scope, $el, $attrs) ->
        bindOnce $scope, "project", (project) ->
            # If the user has not enough permissions we don't enable the sortable
            if not (project.my_permissions.indexOf("modify_us") > -1)
                return

            $el.sortable({
                connectWith: ".sprint-table"
                containment: ".wrapper"
                dropOnEmpty: true
                placeholder: "row us-item-row us-item-drag sortable-placeholder"
                # With scroll activated, it has strange behavior
                # with not full screen browser window.
                scroll: false
                # A consequence of length of backlog user story item
                # the default tolerance ("intersection") not works properly.
                tolerance: "pointer"
                # Revert on backlog is disabled bacause it works bad. Something
                # on the current taiga backlog structure or style makes jquery ui
                # works unexpectly (in some circumstances calculates wrong
                # position for revert).
                revert: false
                cursorAt: {right: 15}
            })

            $el.on "sortreceive", (event, ui) ->
                itemUs = ui.item.scope().us
                itemIndex = ui.item.index()

                deleteElement(ui.item)
                $scope.$emit("sprint:us:move", itemUs, itemIndex, null)
                ui.item.find('a').removeClass('noclick')

            $el.on "sortstop", (event, ui) ->
                # When parent not exists, do nothing
                if ui.item.parent().length == 0
                    return
{'fraction_non_alphanumeric': 0.1445177505497958, 'fraction_numerical': 0.007697141061891298, 'mean_word_length': 2.370566437268396, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5205258', 'n_tokens_mistral': 1756, 'n_tokens_neox': 1630, 'n_words': 577}