lead.storage.factory.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. angular.module('odoo')
  2. .factory('leadsStorageFactory', function () {
  3. // Save lead data to local storage
  4. var save = function (lead, success, error) {
  5. var values = [lead.remote_id ? lead.remote_id : 0, 1, lead.name ? lead.name : '', lead.description ? lead.description : '', lead.contact_name ? lead.contact_name : '', lead.phone ? lead.phone : '', lead.mobile ? lead.mobile : '', lead.fax ? lead.fax : '', lead.street ? lead.street : '', lead.street2 ? lead.street2 : '', lead.meeting_count ? lead.meeting_count : 0, lead.message_bounce ? lead.message_bounce : 0, lead.planned_cost ? lead.planned_cost : 0, lead.planned_revenue ? lead.planned_revenue : 0, lead.priority ? lead.priority : 2, lead.probability ? lead.probability : 0, lead.type ? lead.type : 'lead', lead.partner_id ? lead.partner_id : 0];
  6. var sql = null;
  7. if (lead.id) {
  8. values.push(lead.id);
  9. sql = 'UPDATE lead SET remote_id = ?, modified = ?, modifiedDate = CURRENT_TIMESTAMP, name = ?, description = ?, contact_name = ?, phone = ?, mobile = ?, fax = ?, street = ?, street2 = ?, meeting_count = ?, message_bounce = ?, planned_cost = ?, planned_revenue = ?, priority = ?, probability = ?, type = ?, partner_id = ? WHERE id = ?';
  10. } else {
  11. sql = 'INSERT INTO lead(remote_id, modified, name, description, contact_name, phone, mobile, fax, street, street2, meeting_count, message_bounce, planned_cost, planned_revenue, priority, probability, type, partner_id) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
  12. }
  13. db.executeSql(sql, values, function (result) {
  14. success(sql.startsWith('INSERT') ? result.insertId : lead.id);
  15. }, function (err) {
  16. error(err);
  17. });
  18. }
  19. // Remove lead from local storage
  20. var remove = function (lead, success, error) {
  21. var values = [lead.id];
  22. var sql = null;
  23. if (lead.remote_id) {
  24. sql = 'UPDATE lead SET modified = 2 WHERE id = ?';
  25. } else {
  26. sql = 'DELETE FROM lead WHERE id = ?'
  27. }
  28. db.executeSql(sql, values, function (result) {
  29. success(result.rowsAffected);
  30. }, function(err) {
  31. error(err);
  32. });
  33. }
  34. var removeAll = function (success, error) {
  35. var sql = 'DELETE FROM lead';
  36. db.executeSql(sql, [], function(result) {
  37. success(result.rowsAffected);
  38. }, function(err) {
  39. error(err);
  40. });
  41. }
  42. return {
  43. save: save,
  44. remove: remove,
  45. removeAll: removeAll
  46. }
  47. });