src_js/iconolab-bundle/src/components/mergetool/MergeTool.vue
changeset 146 f912b591e1c1
child 156 e1e14766f608
equal deleted inserted replaced
145:de5736883786 146:f912b591e1c1
       
     1 <script>
       
     2 
       
     3 import Typeahead from '../typeahead/Typeahead.vue'
       
     4 
       
     5 export default {
       
     6 
       
     7 	data () {
       
     8 		return {}
       
     9 	},
       
    10 	
       
    11 	components: {
       
    12 		Typeahead: Typeahead
       
    13 	},
       
    14 
       
    15 	mounted () {
       
    16 
       
    17 		this.targetKeyMap = {
       
    18 			title: "proposal-title", 
       
    19 			desc: "proposal-description",
       
    20 			frag: "proposal-fragment"
       
    21 		};
       
    22 
       
    23 		this.targetFieldTypeMap = {
       
    24 			title: "input", 
       
    25 			desc: "input",
       
    26 			frag: "frag"
       
    27 		};
       
    28 
       
    29 		this.originalValues = {
       
    30 			title: "",
       
    31 			desc: "",
       
    32 			frag: ""
       
    33 		}
       
    34 
       
    35 	},
       
    36 
       
    37 	methods: {
       
    38 
       
    39 		pickProposition: function (event, sourceId, targetKey) {
       
    40 			var value = "";
       
    41 			var source = document.getElementById(sourceId);
       
    42 			var targetField = this.$refs[this.targetKeyMap[targetKey]];
       
    43 			var targetType = this.targetFieldTypeMap[targetKey];
       
    44 			if (!targetType) { throw new Error("A target type must be provided..."); }
       
    45 			
       
    46 			if (targetType === "input") {
       
    47 				value = targetField.value; 
       
    48 				targetField.value = source.value;
       
    49 			}
       
    50 
       
    51 			 if (targetType === "frag") {
       
    52 			 	value = targetField.getAttribute("d");
       
    53 			 	var sourceValue = source.getAttribute("d");
       
    54 			 	var targetPathType = targetField.getAttribute("data-path-type");
       
    55 			 	targetField.setAttribute("d", sourceValue);
       
    56 			 	
       
    57 			 	var pathType = source.getAttribute("data-path-type");
       
    58 			 	pathType = pathType || "FREE";
       
    59 			 	var fragmentField = this.$refs["fragment-field"];
       
    60 			 	fragmentField.value = sourceValue + ";" + pathType;
       
    61 			 }
       
    62 
       
    63 			 this.preserveOriginalValue(targetKey, value);
       
    64 		},
       
    65 
       
    66 		pickTag: function (event, refTag) {
       
    67 			var source = this.$refs[refTag];
       
    68 			var target = this.$refs['proposal-tags'];
       
    69 			this.preserveOriginalValue('proposal-tags', target.tags);
       
    70 			target.setTags(source.tags, true);
       
    71 		},
       
    72 
       
    73 		preserveOriginalValue: function (key, value) {
       
    74 			if (!this.originalValues[key]) {
       
    75 				this.originalValues[key] = value;
       
    76 			}
       
    77 		},
       
    78 
       
    79 		hightlightSource: function (source) {
       
    80 			source.className += "highlight";
       
    81 		},
       
    82 
       
    83 		save: function () {
       
    84 			alert("this is it ... ");
       
    85 		}
       
    86 	}
       
    87 }
       
    88 
       
    89 </script>