Skip to content

Instantly share code, notes, and snippets.

@dariocravero
Created July 22, 2015 16:17
Show Gist options
  • Save dariocravero/6ac48d3724282426cd1e to your computer and use it in GitHub Desktop.
Save dariocravero/6ac48d3724282426cd1e to your computer and use it in GitHub Desktop.
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