[PORTAL-16 PORTAL-18] Widget ms; staging
[portal.git] / ecomp-portal-FE-common / client / app / services / contact-us / contact-us.service.js
index 45c95e9..6158498 100644 (file)
-/*-\r
- * ================================================================================\r
- * ECOMP Portal\r
- * ================================================================================\r
- * Copyright (C) 2017 AT&T Intellectual Property\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *      http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ================================================================================\r
- */\r
-/**\r
- * Created by robertlo on 10/10/2016.\r
- */\r
-'use strict';\r
-\r
-(function () {\r
-    class ContactUsService {\r
-        constructor($q, $log, $http, conf, uuid) {\r
-            this.$q = $q;\r
-            this.$log = $log;\r
-            this.$http = $http;\r
-            this.conf = conf;\r
-            this.uuid = uuid;\r
-        }\r
-        getListOfApp() {\r
-            // this.$log.info('ContactUsService::getListOfavailableApps: get all app list');\r
-            let deferred = this.$q.defer();\r
-            // this.$log.info('ContactUsService::getListOfavailableApps: ', this.conf.api.listOfApp);\r
-            this.$http({\r
-                method: "GET",\r
-                url: this.conf.api.availableApps,           \r
-                cache: false\r
-            }).then( res => {\r
-                // If response comes back as a redirected HTML page which IS NOT a success\r
-               // this.$log.info('ContactUsService::getListOfavailableApps availableApps response: ', res);\r
-                if (Object.keys(res).length == 0) {\r
-                    deferred.reject("ContactUsService::getListOfavailableApps: Failed"); \r
-                } else {\r
-                    // this.$log.debug('ContactUsService::getListOfavailableApps: Succeeded results: ', res);\r
-                    deferred.resolve(res);\r
-                }\r
-            }).catch( status => {\r
-               this.$log.error('ContactUsService::getListOfavailableApps: query error: ',status);\r
-                deferred.reject(status);\r
-            });\r
-            return deferred.promise;           \r
-        }\r
-        \r
-        getContactUs() {\r
-            let deferred = this.$q.defer();\r
-            // this.$log.info('ContactUsService::get all Contact Us list');\r
-            this.$http({\r
-                    url: this.conf.api.getContactUS,\r
-                    method: 'GET',\r
-                    cache: false,\r
-                    headers: {\r
-                        'X-ECOMP-RequestID':this.uuid.generate()\r
-                    }\r
-                }).then(res => {\r
-                    // If response comes back as a redirected HTML page which IS NOT a success\r
-                    if (Object.keys(res.data).length == 0) {\r
-                        deferred.reject("ContactUsService::getContactUs Failed");\r
-                    } else {\r
-                        deferred.resolve(res.data);\r
-                    }\r
-                })\r
-                .catch(status => {\r
-                    deferred.reject(status);\r
-                });\r
-            return deferred.promise;\r
-        }\r
-        \r
-        getAppsAndContacts() {\r
-            let deferred = this.$q.defer();\r
-            // this.$log.info('ContactUsService::getAppsAndContacts');\r
-            this.$http({\r
-                    url: this.conf.api.getAppsAndContacts,\r
-                    method: 'GET',\r
-                    cache: false,\r
-                    headers: {\r
-                        'X-ECOMP-RequestID':this.uuid.generate()\r
-                    }\r
-                }).then(res => {\r
-                    // If response comes back as a redirected HTML page which IS NOT a success\r
-                    if (Object.keys(res.data).length == 0) {\r
-                        deferred.reject("ContactUsService::getAppsAndContacts Failed");\r
-                    } else {\r
-                        deferred.resolve(res.data);\r
-                    }\r
-                })\r
-                .catch(status => {\r
-                    deferred.reject(status);\r
-                });\r
-            return deferred.promise;\r
-        }\r
-\r
-        getContactUSPortalDetails(){\r
-               let deferred = this.$q.defer();\r
-            // this.$log.info('ContactUsService::get all Contact Us Portal Details');\r
-            this.$http({\r
-                    url: this.conf.api.getContactUSPortalDetails,\r
-                    method: 'GET',\r
-                    cache: false,\r
-                    headers: {\r
-                        'X-ECOMP-RequestID':this.uuid.generate()\r
-                    }\r
-                }).then(res => {\r
-                    // If response comes back as a redirected HTML page which IS NOT a success\r
-                    if (Object.keys(res.data).length == 0) {\r
-                        deferred.reject("ContactUsService::getContactUSPortalDetails Failed");\r
-                    } else {\r
-                        deferred.resolve(res.data);\r
-                    }\r
-                })\r
-                .catch(status => {\r
-                    deferred.reject(status);\r
-                });\r
-            return deferred.promise;\r
-        }\r
-\r
-        getAppCategoryFunctions(){\r
-               let deferred = this.$q.defer();\r
-            // this.$log.info('ContactUsService::get all App Category Functions');\r
-            this.$http({\r
-                    url: this.conf.api.getAppCategoryFunctions,\r
-                    method: 'GET',\r
-                    cache: false,\r
-                    headers: {\r
-                        'X-ECOMP-RequestID':this.uuid.generate()\r
-                    }\r
-                }).then(res => {\r
-                    // If response comes back as a redirected HTML page which IS NOT a success\r
-                    if (Object.keys(res.data).length == 0) {\r
-                        deferred.reject("ContactUsService::getAppCategoryFunctions Failed");\r
-                    } else {\r
-                        deferred.resolve(res.data);\r
-                    }\r
-                })\r
-                .catch(status => {\r
-                    deferred.reject(status);\r
-                });\r
-            return deferred.promise;\r
-        }\r
-        \r
-        addContactUs(newContactUs) {\r
-               // this.$log.info('ContactUsService::add a new Contact Us');\r
-               // this.$log.info(newContactUs)\r
-               let deferred = this.$q.defer();\r
-            // this.$log.info('ContactUsService:: add Contact Us' + JSON.stringify(newContactUs));\r
-            \r
-            var contactUsObj={\r
-                       appId:newContactUs.app.value,\r
-                       appName:newContactUs.app.title,\r
-                       description:newContactUs.desc,\r
-                       contactName:newContactUs.name,\r
-                       contactEmail:newContactUs.email,\r
-                       url:newContactUs.url,                           \r
-            };\r
-            this.$http({\r
-                url: this.conf.api.saveContactUS,\r
-                method: 'POST',\r
-                cache: false,\r
-                headers: {\r
-                    'X-ECOMP-RequestID':this.uuid.generate()\r
-                },\r
-                data: contactUsObj\r
-            }).then(res => {\r
-                // this.$log.info('ContactUsService:: add Contact Us res' ,res);\r
-                // If response comes back as a redirected HTML page which IS NOT a success\r
-                if (res==null || Object.keys(res.data).length == 0 || res.data.message == 'failure') {\r
-                    deferred.reject("Add Contact Us failed");\r
-                    this.$log.error('ContactUsService:: add Contact Us failed');\r
-                } else {\r
-                    deferred.resolve(res.data);\r
-                }\r
-            }).catch(errRes => {\r
-                   deferred.reject(errRes);\r
-             });\r
-            return deferred.promise;\r
-        }\r
-        \r
-        modifyContactUs(contactUsObj) {\r
-               // this.$log.info('ContactUsService::edit Contact Us',contactUsObj);            \r
-               let deferred = this.$q.defer();\r
-            this.$http({\r
-                url: this.conf.api.saveContactUS,\r
-                method: 'POST',\r
-                cache: false,\r
-                headers: {\r
-                    'X-ECOMP-RequestID':this.uuid.generate()\r
-                },\r
-                data: contactUsObj\r
-            }).then(res => {\r
-                // this.$log.info('ContactUsService:: edit Contact Us res' ,res);\r
-                // If response comes back as a redirected HTML page which IS NOT a success\r
-                if (res==null || Object.keys(res.data).length == 0 || res.data.message == 'failure') {\r
-                    deferred.reject("Edit Contact Us failed");\r
-                    this.$log.error('ContactUsService:: edit Contact Us failed');\r
-                } else {\r
-                    deferred.resolve(res.data);\r
-                }\r
-            }).catch(errRes => {\r
-                   deferred.reject(errRes);\r
-             });\r
-            return deferred.promise;\r
-        }\r
-\r
-        removeContactUs(id) {\r
-            let deferred = this.$q.defer();\r
-            let url = this.conf.api.deleteContactUS + '/' + id;\r
-            // this.$log.info('ContactUsService:: remove Contact Us');\r
-            this.$http({\r
-                url: url,\r
-                method: 'POST',\r
-                cache: false,\r
-                data: '',\r
-                headers: {\r
-                    'X-ECOMP-RequestID':this.uuid.generate()\r
-                }\r
-            }).then(res => {\r
-                // If response comes back as a redirected HTML page which IS NOT a success\r
-               // this.$log.info("ContactUsService::removeContactUs res",res);\r
-               deferred.resolve(res.data);\r
-                if (Object.keys(res.data).length == 0) {\r
-                    deferred.reject("ContactUsService::removeContactUs Failed");\r
-                } else {\r
-                    deferred.resolve(res.data);\r
-                }\r
-            }).catch(errRes => {\r
-                deferred.reject(errRes);\r
-            });\r
-\r
-            return deferred.promise;\r
-        }\r
-    }\r
-    ContactUsService.$inject = ['$q', '$log', '$http', 'conf', 'uuid4'];\r
-    angular.module('ecompApp').service('contactUsService', ContactUsService)\r
-})();\r
+/*-
+ * ================================================================================
+ * ECOMP Portal
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ================================================================================
+ */
+/**
+ * Created by robertlo on 10/10/2016.
+ */
+'use strict';
+
+(function () {
+    class ContactUsService {
+        constructor($q, $log, $http, conf, uuid) {
+            this.$q = $q;
+            this.$log = $log;
+            this.$http = $http;
+            this.conf = conf;
+            this.uuid = uuid;
+        }
+        getListOfApp() {
+            // this.$log.info('ContactUsService::getListOfavailableApps: get all app list');
+            let deferred = this.$q.defer();
+            // this.$log.info('ContactUsService::getListOfavailableApps: ', this.conf.api.listOfApp);
+            this.$http({
+                method: "GET",
+                url: this.conf.api.availableApps,           
+                cache: false
+            }).then( res => {
+                // If response comes back as a redirected HTML page which IS NOT a success
+               // this.$log.info('ContactUsService::getListOfavailableApps availableApps response: ', res);
+                if (Object.keys(res).length == 0) {
+                    deferred.reject("ContactUsService::getListOfavailableApps: Failed"); 
+                } else {
+                    // this.$log.debug('ContactUsService::getListOfavailableApps: Succeeded results: ', res);
+                    deferred.resolve(res);
+                }
+            }).catch( status => {
+               this.$log.error('ContactUsService::getListOfavailableApps: query error: ',status);
+                deferred.reject(status);
+            });
+            return deferred.promise;           
+        }
+        
+        getContactUs() {
+            let deferred = this.$q.defer();
+            // this.$log.info('ContactUsService::get all Contact Us list');
+            this.$http({
+                    url: this.conf.api.getContactUS,
+                    method: 'GET',
+                    cache: false,
+                    headers: {
+                        'X-ECOMP-RequestID':this.uuid.generate()
+                    }
+                }).then(res => {
+                    // If response comes back as a redirected HTML page which IS NOT a success
+                    if (Object.keys(res.data).length == 0) {
+                        deferred.reject("ContactUsService::getContactUs Failed");
+                    } else {
+                        deferred.resolve(res.data);
+                    }
+                })
+                .catch(status => {
+                    deferred.reject(status);
+                });
+            return deferred.promise;
+        }
+        
+        getAppsAndContacts() {
+            let deferred = this.$q.defer();
+            // this.$log.info('ContactUsService::getAppsAndContacts');
+            this.$http({
+                    url: this.conf.api.getAppsAndContacts,
+                    method: 'GET',
+                    cache: false,
+                    headers: {
+                        'X-ECOMP-RequestID':this.uuid.generate()
+                    }
+                }).then(res => {
+                    // If response comes back as a redirected HTML page which IS NOT a success
+                    if (Object.keys(res.data).length == 0) {
+                        deferred.reject("ContactUsService::getAppsAndContacts Failed");
+                    } else {
+                        deferred.resolve(res.data);
+                    }
+                })
+                .catch(status => {
+                    deferred.reject(status);
+                });
+            return deferred.promise;
+        }
+
+        getContactUSPortalDetails(){
+               let deferred = this.$q.defer();
+            // this.$log.info('ContactUsService::get all Contact Us Portal Details');
+            this.$http({
+                    url: this.conf.api.getContactUSPortalDetails,
+                    method: 'GET',
+                    cache: false,
+                    headers: {
+                        'X-ECOMP-RequestID':this.uuid.generate()
+                    }
+                }).then(res => {
+                    // If response comes back as a redirected HTML page which IS NOT a success
+                    if (Object.keys(res.data).length == 0) {
+                        deferred.reject("ContactUsService::getContactUSPortalDetails Failed");
+                    } else {
+                        deferred.resolve(res.data);
+                    }
+                })
+                .catch(status => {
+                    deferred.reject(status);
+                });
+            return deferred.promise;
+        }
+
+        getAppCategoryFunctions(){
+               let deferred = this.$q.defer();
+            // this.$log.info('ContactUsService::get all App Category Functions');
+            this.$http({
+                    url: this.conf.api.getAppCategoryFunctions,
+                    method: 'GET',
+                    cache: false,
+                    headers: {
+                        'X-ECOMP-RequestID':this.uuid.generate()
+                    }
+                }).then(res => {
+                    // If response comes back as a redirected HTML page which IS NOT a success
+                    if (Object.keys(res.data).length == 0) {
+                        deferred.reject("ContactUsService::getAppCategoryFunctions Failed");
+                    } else {
+                        deferred.resolve(res.data);
+                    }
+                })
+                .catch(status => {
+                    deferred.reject(status);
+                });
+            return deferred.promise;
+        }
+        
+        addContactUs(newContactUs) {
+               // this.$log.info('ContactUsService::add a new Contact Us');
+               // this.$log.info(newContactUs)
+               let deferred = this.$q.defer();
+            // this.$log.info('ContactUsService:: add Contact Us' + JSON.stringify(newContactUs));
+            
+            var contactUsObj={
+                       appId:newContactUs.app.value,
+                       appName:newContactUs.app.title,
+                       description:newContactUs.desc,
+                       contactName:newContactUs.name,
+                       contactEmail:newContactUs.email,
+                       url:newContactUs.url,                           
+            };
+            this.$http({
+                url: this.conf.api.saveContactUS,
+                method: 'POST',
+                cache: false,
+                headers: {
+                    'X-ECOMP-RequestID':this.uuid.generate()
+                },
+                data: contactUsObj
+            }).then(res => {
+                // this.$log.info('ContactUsService:: add Contact Us res' ,res);
+                // If response comes back as a redirected HTML page which IS NOT a success
+                if (res==null || Object.keys(res.data).length == 0 || res.data.message == 'failure') {
+                    deferred.reject("Add Contact Us failed");
+                    this.$log.error('ContactUsService:: add Contact Us failed');
+                } else {
+                    deferred.resolve(res.data);
+                }
+            }).catch(errRes => {
+                   deferred.reject(errRes);
+             });
+            return deferred.promise;
+        }
+        
+        modifyContactUs(contactUsObj) {
+               // this.$log.info('ContactUsService::edit Contact Us',contactUsObj);            
+               let deferred = this.$q.defer();
+            this.$http({
+                url: this.conf.api.saveContactUS,
+                method: 'POST',
+                cache: false,
+                headers: {
+                    'X-ECOMP-RequestID':this.uuid.generate()
+                },
+                data: contactUsObj
+            }).then(res => {
+                // this.$log.info('ContactUsService:: edit Contact Us res' ,res);
+                // If response comes back as a redirected HTML page which IS NOT a success
+                if (res==null || Object.keys(res.data).length == 0 || res.data.message == 'failure') {
+                    deferred.reject("Edit Contact Us failed");
+                    this.$log.error('ContactUsService:: edit Contact Us failed');
+                } else {
+                    deferred.resolve(res.data);
+                }
+            }).catch(errRes => {
+                   deferred.reject(errRes);
+             });
+            return deferred.promise;
+        }
+
+        removeContactUs(id) {
+            let deferred = this.$q.defer();
+            let url = this.conf.api.deleteContactUS + '/' + id;
+            // this.$log.info('ContactUsService:: remove Contact Us');
+            this.$http({
+                url: url,
+                method: 'POST',
+                cache: false,
+                data: '',
+                headers: {
+                    'X-ECOMP-RequestID':this.uuid.generate()
+                }
+            }).then(res => {
+                // If response comes back as a redirected HTML page which IS NOT a success
+               // this.$log.info("ContactUsService::removeContactUs res",res);
+               deferred.resolve(res.data);
+                if (Object.keys(res.data).length == 0) {
+                    deferred.reject("ContactUsService::removeContactUs Failed");
+                } else {
+                    deferred.resolve(res.data);
+                }
+            }).catch(errRes => {
+                deferred.reject(errRes);
+            });
+
+            return deferred.promise;
+        }
+    }
+    ContactUsService.$inject = ['$q', '$log', '$http', 'conf', 'uuid4'];
+    angular.module('ecompApp').service('contactUsService', ContactUsService)
+})();