|
@@ -0,0 +1,102 @@
|
|
|
+angular.module('odoo')
|
|
|
+
|
|
|
+ /**
|
|
|
+ * -----------------------------------------------------------------------------
|
|
|
+ * Description: Local storage manager for crm stage data
|
|
|
+ * -----------------------------------------------------------------------------
|
|
|
+ */
|
|
|
+ .factory('crmStagesDataFactory', function (
|
|
|
+ crmStagesStorageFactory,
|
|
|
+ odooInteroperabilityFactory,
|
|
|
+ configFactory,
|
|
|
+ sqlFactory,
|
|
|
+ asyncLoopFactory
|
|
|
+ ) {
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ var pull = function (id, success, error) {
|
|
|
+ configFactory(function (configuration) {
|
|
|
+ if (id) {
|
|
|
+
|
|
|
+ odooInteroperabilityFactory.read('crm.case.stage', [['id', '=', id]], configuration, function (response) {
|
|
|
+ success(response);
|
|
|
+ }, function (odooErr) {
|
|
|
+ error(odooErr);
|
|
|
+ });
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ odooInteroperabilityFactory.read('crm.case.stage', [], configuration, function (response) {
|
|
|
+ success(response);
|
|
|
+ }, function (odooErr) {
|
|
|
+ error(odooErr)
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+ }, function (configErr) {
|
|
|
+ error(configErr);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ var push = function (id, data, success, error) {
|
|
|
+ // TODO
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ var destroy = function (id, success, error) {
|
|
|
+ // TODO
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ var getAll = function (success, error) {
|
|
|
+ sqlFactory.select('crm_stage', function (stages) {
|
|
|
+ success(stages);
|
|
|
+ }, function (selectErr) {
|
|
|
+ error(selectErr);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ var sync = function (success, error) {
|
|
|
+ pull(0, function (stages) {
|
|
|
+ crmStagesStorageFactory.removeAll(function () {
|
|
|
+ asyncLoopFactory(stages.length, function (loop) {
|
|
|
+ var data = stages[loop.iteration()];
|
|
|
+
|
|
|
+ crmStagesStorageFactory.save(data, function () {
|
|
|
+ loop.next();
|
|
|
+ }, function (saveErr) {
|
|
|
+ loop.next();
|
|
|
+ });
|
|
|
+
|
|
|
+ // End loop
|
|
|
+ }, function () {
|
|
|
+ success(stages);
|
|
|
+ });
|
|
|
+ }, function (removeAllErr) {
|
|
|
+ error(removeAllErr);
|
|
|
+ });
|
|
|
+ }, function (pullErr) {
|
|
|
+ error(pullErr);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ return {
|
|
|
+ pull: pull,
|
|
|
+ push: push,
|
|
|
+ destroy: destroy,
|
|
|
+ sync: sync
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|