mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
1a92e1b664
[web] Add eslint rules for angularjs components GitOrigin-RevId: 1343d584368faeb912f04c5879228bcbd07a042a
108 lines
2.8 KiB
JavaScript
108 lines
2.8 KiB
JavaScript
/* eslint-disable
|
|
max-len,
|
|
no-return-assign,
|
|
*/
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
// Fix any style issues and re-enable lint.
|
|
/*
|
|
* decaffeinate suggestions:
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
* DS207: Consider shorter variations of null checks
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
*/
|
|
import App from '../base'
|
|
App.directive('selectAllList', function () {
|
|
return {
|
|
controller: [
|
|
'$scope',
|
|
function ($scope) {
|
|
// Selecting or deselecting all should apply to all projects
|
|
this.selectAll = () => $scope.$broadcast('select-all:select')
|
|
|
|
this.deselectAll = () => $scope.$broadcast('select-all:deselect')
|
|
|
|
this.clearSelectAllState = () => $scope.$broadcast('select-all:clear')
|
|
},
|
|
],
|
|
link(scope, element, attrs) {},
|
|
}
|
|
})
|
|
|
|
App.directive('selectAll', function () {
|
|
return {
|
|
require: '^selectAllList',
|
|
link(scope, element, attrs, selectAllListController) {
|
|
scope.$on('select-all:clear', () => element.prop('checked', false))
|
|
|
|
return element.change(function () {
|
|
if (element.is(':checked')) {
|
|
selectAllListController.selectAll()
|
|
} else {
|
|
selectAllListController.deselectAll()
|
|
}
|
|
return true
|
|
})
|
|
},
|
|
}
|
|
})
|
|
|
|
App.directive('selectIndividual', function () {
|
|
return {
|
|
require: '^selectAllList',
|
|
scope: {
|
|
ngModel: '=',
|
|
},
|
|
link(scope, element, attrs, selectAllListController) {
|
|
let ignoreChanges = false
|
|
|
|
scope.$watch('ngModel', function (value) {
|
|
if (value != null && !ignoreChanges) {
|
|
return selectAllListController.clearSelectAllState()
|
|
}
|
|
})
|
|
|
|
scope.$on('select-all:select', function () {
|
|
if (element.prop('disabled')) {
|
|
return
|
|
}
|
|
ignoreChanges = true
|
|
scope.$apply(() => (scope.ngModel = true))
|
|
return (ignoreChanges = false)
|
|
})
|
|
|
|
scope.$on('select-all:deselect', function () {
|
|
if (element.prop('disabled')) {
|
|
return
|
|
}
|
|
ignoreChanges = true
|
|
scope.$apply(() => (scope.ngModel = false))
|
|
return (ignoreChanges = false)
|
|
})
|
|
|
|
return scope.$on('select-all:row-clicked', function () {
|
|
if (element.prop('disabled')) {
|
|
return
|
|
}
|
|
ignoreChanges = true
|
|
scope.$apply(function () {
|
|
scope.ngModel = !scope.ngModel
|
|
if (!scope.ngModel) {
|
|
return selectAllListController.clearSelectAllState()
|
|
}
|
|
})
|
|
return (ignoreChanges = false)
|
|
})
|
|
},
|
|
}
|
|
})
|
|
|
|
export default App.directive('selectRow', function () {
|
|
return {
|
|
scope: true,
|
|
link(scope, element, attrs) {
|
|
return element.on('click', e =>
|
|
scope.$broadcast('select-all:row-clicked')
|
|
)
|
|
},
|
|
}
|
|
})
|