{"id":242,"date":"2015-04-20T22:41:06","date_gmt":"2015-04-20T22:41:06","guid":{"rendered":"https:\/\/www.tech.shinynewthings.com\/?p=242"},"modified":"2015-04-20T22:41:06","modified_gmt":"2015-04-20T22:41:06","slug":"angularjs-utilities","status":"publish","type":"post","link":"https:\/\/www.tech.shinynewthings.com\/?p=242","title":{"rendered":"AngularJS &#8211; Utilities"},"content":{"rendered":"<p>&#8216;use strict&#8217;;<\/p>\n<p>\/**<br \/>\n * @ngdoc service<br \/>\n * @name interceptcms.utilities<br \/>\n * @description<br \/>\n * # utilities<br \/>\n * Service in the interceptcms.<br \/>\n *\/<\/p>\n<p>var initInjector = angular.injector([&#8216;ng&#8217;]);<br \/>\nvar $http = initInjector.get(&#8216;$http&#8217;);<\/p>\n<p>angular.module(&#8216;interceptcms&#8217;).service(&#8216;utils&#8217;, function () {<\/p>\n<pre><code>var utilities = {\n\n    \/\/ PRESUBMIT OBJECT MODIFICATION\n    \/\/ REMOVE UNCHANGED PROPERTIES BEFORE UPDATE\n    \/\/ ONLY SUBMIT CHANGED PROPS\n\n    \/\/ OBJECTS PROPERTIES ARE COMPARED TO THE ORIGINAL OBJECT\n    \/\/ ONLY CHANGED VALUES ARE SUBMITTED TO THE DB\n    \/\/ VALUES THAT MATCH THE ORIGINAL OBJECT ARE STRIPPED BEFORE SUBMITTING\n\n    \/\/ ALLOWS US TO TRACK THE CHANGED PROPS IN THE SUBMITTED OBJ\n    compareObjectsKeepChanges: function (originalObj, editedObj){\n        for(var prop in editedObj) {\n            if (typeof originalObj[prop] === \"object\") {\n                if (this.jsonObj(originalObj[prop]) === this.jsonObj(editedObj[prop])) {\n                    delete editedObj[prop];\n                }\n            } else {\n                if (editedObj[prop] === originalObj[prop]) {\n                    delete editedObj[prop];\n                }\n            }\n        }\n        if (!this.isObject(editedObj)) {\n            return;\n        } else {\n            return editedObj;\n        }\n    },\n\n    \/\/ VERIFY THAT THERE IS OBJECT\n    isObject: function (newObj) {\n        return (Object.keys(newObj).length &gt; 0);\n    },\n\n    \/\/ STRINGIFY OBJECT ARRAYS OR OBJECTS WITHIN AN OBJECT\n    jsonObj: function (obj) {\n        return JSON.stringify(obj);\n    },\n\n    \/\/ REMOVE PROPERTIES FROM OBJECT\n    stripObj: function (obj, propsToRemove) {\n        if (obj) {\n            for (var i = propsToRemove.length; i &gt;= 0; i--) {\n                if (obj[propsToRemove[i]]) {\n                    delete obj[propsToRemove[i]];\n                }\n            }\n        }\n        return obj;\n    },\n\n    getUrl: function(url) {\n        $http.get(url).success(function(obj) {\n            return obj;\n        }).error(function(err){\n            return err;\n        });\n    }\n};\n\nreturn utilities;\n<\/code><\/pre>\n<p>});<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8216;use strict&#8217;; \/** * @ngdoc service * @name interceptcms.utilities * @description * # utilities * Service in the interceptcms. *\/ var initInjector = angular.injector([&#8216;ng&#8217;]); var $http = initInjector.get(&#8216;$http&#8217;); angular.module(&#8216;interceptcms&#8217;).service(&#8216;utils&#8217;, function () { var utilities = { \/\/ PRESUBMIT OBJECT MODIFICATION \/\/ REMOVE UNCHANGED PROPERTIES BEFORE UPDATE \/\/ ONLY SUBMIT CHANGED PROPS \/\/ OBJECTS PROPERTIES ARE [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-242","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/posts\/242","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=242"}],"version-history":[{"count":1,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/posts\/242\/revisions"}],"predecessor-version":[{"id":243,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/posts\/242\/revisions\/243"}],"wp:attachment":[{"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=242"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=242"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}