-
-
Save MasoodGit/0e5fc27d28c084c9ce0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.directive("panelWidgetResourceSend", ["$http", "$rootScope", "$timeout", function($http) { | |
return { | |
restrict: "A", | |
controller: ["$scope", "$element", function($scope, $element) { | |
$scope.sent = !1, | |
$scope.sending = !1, | |
$scope.failed = !1, | |
$scope.sendResource = function($event) { | |
if ($scope.resource) { | |
if ($scope.resource.$invalid) { | |
$event.preventDefault(); | |
var invalidResources = $element[0].getElementsByClassName("ng-invalid"); | |
angular.forEach(invalidResources, function() { | |
$scope.resource.$dirty = !0 | |
} | |
); | |
var input, errorField = invalidResources[0]; | |
return void (errorField && ($scope.$emit("panel:scrollTo", errorField, { | |
animate: !0 | |
}), | |
input = errorField.querySelectorAll("input, textarea")[0], | |
("radio" !== input.type || "checkbox" !== input.type) && input.focus())) | |
} | |
var resources = {}; | |
$scope.widgets.forEach(function(widget) { | |
widget.element.match(/^resource/) && "resource_send" !== widget.element && widget.data.value && (resources[widget.id] = widget.data.value) | |
} | |
), | |
$scope.sending = !0, | |
$http.put("/-panels/resource", { | |
panel_id: $scope.id, | |
resources: resources | |
}).success($scope.resourceSuccess).error($scope.resourceError) | |
} | |
} | |
, | |
$scope.resourceSuccess = function() { | |
$scope.sending = !1, | |
$scope.sent = !0 | |
} | |
, | |
$scope.resourceError = function() { | |
$scope.sending = !1, | |
$scope.failed = !0 | |
} | |
} | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment