Guest User

Untitled

a guest
May 25th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. <template>
  2. <div id="page_content_inner">
  3. <h3 class="heading_b uk-margin-bottom">{{ $t('contacts.createPageTitle') }}</h3>
  4. <div class="md-card">
  5. <div class="md-card-content large-padding">
  6. <create-form :contact="contact" :validRules="validRules"></create-form>
  7. </div>
  8. </div>
  9. </div>
  10. </template>
  11.  
  12. <script>
  13. // mixins
  14. import ContactsMixin from 'crm/mixins/Contacts';
  15. import ContactTypesMixin from 'crm/mixins/ContactTypes';
  16.  
  17. // components
  18. import CreateForm from 'crm/pages/contacts/includes/CreateForm';
  19.  
  20. const initialAddress = {
  21. name: "",
  22. value_one: "",
  23. value_two: "",
  24. value_three: "",
  25. house_number: "",
  26. post_code: "",
  27. land_id: null,
  28. };
  29.  
  30. export default {
  31. name: 'crm-contacts-create',
  32. data: () => {
  33. return {
  34. validRules: {
  35. address: {
  36. name: { required: true, min: 3 },
  37. value_one: { required: true, min: 3 },
  38. value_two: { min: 3 },
  39. value_three: { min: 3 },
  40. house_number: { numeric: true, min:1 },
  41. post_code: { numeric: true },
  42. land: { required: true },
  43. },
  44. company_name: { min: 3 },
  45. company_tax_number: { min: 2, numeric: true },
  46. notes: { min: 10 },
  47. type: { required: true, in: "0,1" },
  48. client_shortcode: { min: 3 },
  49. client_number: { min: 3, numeric: true },
  50. project_manager_id: { numeric: true },
  51. price_list: { numeric: true },
  52. person_birthday: { date_format: 'DD.MM.YYYY' },
  53. person_department: { min: 3 },
  54. person_position: { min: 3 },
  55. person_title: { min: 3 },
  56. first_name: { min: 3 },
  57. last_name: { min: 3 },
  58. },
  59. contact: {
  60. type: 0, // company
  61. is_client: 0,
  62. is_provider: 0,
  63. // company info
  64. company_name: '',
  65. company_tax_number: '',
  66. avatar: '',
  67. base_64_avatar: null,
  68. // addresses
  69. addresses: [ initialAddress ],
  70. // contact possibilities
  71. possibilities: [],
  72. // general
  73. notes: '',
  74. tags: [],
  75. // client info
  76. client_shortcode: '',
  77. client_number: '',
  78. project_manager_id: 0,
  79. price_list: '',
  80. // provider info
  81. provider_number: '',
  82. // person
  83. person_title: '',
  84. first_name: '',
  85. last_name: '',
  86. // additional information
  87. person_birthday: null,
  88. person_department: '',
  89. person_position: ''
  90. }
  91. }
  92. },
  93. mixins: [
  94. ContactTypesMixin,
  95. ContactsMixin
  96. ],
  97. components: {
  98. 'create-form': CreateForm
  99. },
  100. mounted: function () {
  101. this.Bus.$emit('pageIsReady');
  102. this.Bus.$on('storeContact', this.storeContact);
  103. this.Bus.$on('modal.cropper.change', this.updateAvatar);
  104. this.Bus.$on('crm.contact-types.update', this.updatePossibilities);
  105. this.Bus.$on('crm.address.new', this.newAddress);
  106. this.Bus.$on('crm.address.update', this.updateAddress);
  107. this.Bus.$on('crm.address.remove', this.removeAddress);
  108. this.Bus.$on('global.tags-input.update', this.updateTags);
  109. },
  110. methods: {
  111. updateAvatar: function (data) {
  112. this.contact.base_64_avatar = data.imageSrc;
  113. },
  114. updatePossibilities: function (data) {
  115. this.contact.possibilities = this.objectToArray(data.items);
  116. },
  117. newAddress: function () {
  118. this.contact.addresses.push(initialAddress);
  119. },
  120. updateAddress: function (data) {
  121. this.contact.addresses[data.index] = data.address;
  122. },
  123. removeAddress: function (data) {
  124. let addresses = this.contact.addresses;
  125.  
  126. if (addresses.length === 1) {
  127. this.fail('address.lastAddressDelete');
  128. return false;
  129. }
  130.  
  131. delete addresses[data.index];
  132. addresses = addresses.filter(function (val) { return val });
  133. this.contact.addresses = addresses;
  134. },
  135. updateTags: function (data) {
  136. this.contact.tags = data.tags;
  137. }
  138. }
  139. }
  140. </script>
  141.  
  142. <style lang="sass-loader" scoped></style>
Add Comment
Please, Sign In to add comment