{I" class:ETI"BundledAsset;FI"logical_path;TI"3hyper_admin/angularjs/controllers/form_ctrl.js;FI" pathname;TI"u/home/sindre/Code/hyper/hyper_admin/app/assets/javascripts/hyper_admin/angularjs/controllers/form_ctrl.js.coffee;FI"content_type;TI"application/javascript;TI" mtime;Tl+نع)TI" length;Tiَ I" digest;TI"%c9004231fbd6116666e59e9aa942b6e7;FI" source;TI"َ (function() { var __hasProp = {}.hasOwnProperty; angular.module("hyperadmin").controller("FormCtrl", function($scope, $state, Restangular, Flash) { var method, mode, prettifyErrors, successMessage, target; this.resource = {}; mode = $state.current.data.mode; if (mode === "new") { method = "post"; target = "admin/" + $scope.resourceClass.plural; successMessage = "" + $scope.resourceClass.singular_human + " created successfully."; } else { method = "patch"; target = "admin/" + $scope.resourceClass.plural + "/" + $state.params.id; successMessage = "" + $scope.resourceClass.singular_human + " updated successfully."; Restangular.one(target).get().then((function(_this) { return function(resource) { _this.resource = resource; return $scope.resourceClass.form_attributes.forEach(function(attr) { if (attr.type === "date" || attr.type === "datetime") { if (_this.resource[attr.key]) { return _this.resource[attr.key] = new Date(_this.resource[attr.key]); } } }); }; })(this)); } ["id", "created_at", "updated_at"].forEach(function(key) { return _.remove($scope.resourceClass.form_attributes, function(attr) { return attr.key === key; }); }); prettifyErrors = function(errors) { var attr, attrSchema, result; result = {}; for (attr in errors) { if (!__hasProp.call(errors, attr)) continue; attrSchema = _.find($scope.resourceClass.form_attributes, (function(_this) { return function(attribute) { return attribute.key === attr; }; })(this)); result[attrSchema.human] = errors[attr]; } return result; }; this.submit = (function(_this) { return function() { var onError, onSuccess; onError = function(response) { return _this.errors = prettifyErrors(response.data); }; onSuccess = function(resource) { $state.go("^.show", { id: resource.id }); return Flash.setMessage("success", successMessage); }; if (method === "post") { return Restangular.all(target).post(_this.resource).then(onSuccess, onError); } else if (method === "patch") { return Restangular.one(target).patch(_this.resource).then(onSuccess, onError); } }; })(this); return this; }); }).call(this); ;TI"required_assets_digest;TI"%c1ebe86203eb62fde83a2862a7116711;FI" _version;TI"%6584930913c75ff69ba506e1cfbae2c9;F