| author | Harris Baptiste <harris.baptiste@iri.centrepompidou.fr> |
| Tue, 30 Aug 2016 16:58:59 +0200 | |
| changeset 156 | e1e14766f608 |
| parent 146 | f912b591e1c1 |
| child 539 | 08e2513dbc2f |
| permissions | -rw-r--r-- |
|
146
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
1 |
<script> |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
2 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
3 |
import Typeahead from '../typeahead/Typeahead.vue' |
|
156
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
4 |
import DiffViewer from '../diffviewer/diffviewer.vue' |
|
146
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
5 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
6 |
export default {
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
7 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
8 |
data () {
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
9 |
return {}
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
10 |
}, |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
11 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
12 |
components: {
|
|
156
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
13 |
Typeahead: Typeahead, |
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
14 |
'diffviewer': DiffViewer |
|
146
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
15 |
}, |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
16 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
17 |
mounted () {
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
18 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
19 |
this.targetKeyMap = {
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
20 |
title: "proposal-title", |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
21 |
desc: "proposal-description", |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
22 |
frag: "proposal-fragment" |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
23 |
}; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
24 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
25 |
this.targetFieldTypeMap = {
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
26 |
title: "input", |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
27 |
desc: "input", |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
28 |
frag: "frag" |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
29 |
}; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
30 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
31 |
this.originalValues = {
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
32 |
title: "", |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
33 |
desc: "", |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
34 |
frag: "" |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
35 |
} |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
36 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
37 |
}, |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
38 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
39 |
methods: {
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
40 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
41 |
pickProposition: function (event, sourceId, targetKey) {
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
42 |
var value = ""; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
43 |
var source = document.getElementById(sourceId); |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
44 |
var targetField = this.$refs[this.targetKeyMap[targetKey]]; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
45 |
var targetType = this.targetFieldTypeMap[targetKey]; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
46 |
if (!targetType) { throw new Error("A target type must be provided..."); }
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
47 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
48 |
if (targetType === "input") {
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
49 |
value = targetField.value; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
50 |
targetField.value = source.value; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
51 |
} |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
52 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
53 |
if (targetType === "frag") {
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
54 |
value = targetField.getAttribute("d");
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
55 |
var sourceValue = source.getAttribute("d");
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
56 |
var targetPathType = targetField.getAttribute("data-path-type");
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
57 |
targetField.setAttribute("d", sourceValue);
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
58 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
59 |
var pathType = source.getAttribute("data-path-type");
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
60 |
pathType = pathType || "FREE"; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
61 |
var fragmentField = this.$refs["fragment-field"]; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
62 |
fragmentField.value = sourceValue + ";" + pathType; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
63 |
} |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
64 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
65 |
this.preserveOriginalValue(targetKey, value); |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
66 |
}, |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
67 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
68 |
pickTag: function (event, refTag) {
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
69 |
var source = this.$refs[refTag]; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
70 |
var target = this.$refs['proposal-tags']; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
71 |
this.preserveOriginalValue('proposal-tags', target.tags);
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
72 |
target.setTags(source.tags, true); |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
73 |
}, |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
74 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
75 |
preserveOriginalValue: function (key, value) {
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
76 |
if (!this.originalValues[key]) {
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
77 |
this.originalValues[key] = value; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
78 |
} |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
79 |
}, |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
80 |
|
|
156
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
81 |
showDiffviewer: function (refId, sourceId, targetKey) {
|
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
82 |
|
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
83 |
var sourceField = document.getElementById(sourceId); |
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
84 |
var targetField = this.$refs[this.targetKeyMap[targetKey]]; |
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
85 |
var targetType = this.targetFieldTypeMap[targetKey]; |
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
86 |
var diffViewer = this.$refs[refId]; |
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
87 |
|
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
88 |
if (!diffViewer) { throw new Error("The DiffViewer can't be found for " + targetKey); }
|
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
89 |
|
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
90 |
if (targetType === "input") {
|
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
91 |
diffViewer.showTextDiff(sourceField.value, targetField.value); |
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
92 |
} |
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
93 |
|
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
94 |
if (targetKey === "tag") {
|
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
95 |
var source = this.$refs[sourceId]; |
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
96 |
var target = this.$refs['proposal-tags']; |
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
97 |
if ((source.tags.length !== 0) && (target.tags.length !== 0)) {
|
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
98 |
diffViewer.showTagDiff(source.tags, target.tags); |
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
99 |
} |
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
100 |
} |
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
101 |
/* frag */ |
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
102 |
if ( targetKey === "frag") {
|
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
103 |
|
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
104 |
var originalPath = targetField.getAttribute("d");
|
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
105 |
var modifiedPath = sourceField.getAttribute("d");
|
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
106 |
diffViewer.showFragmentDiff(originalPath, modifiedPath); |
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
107 |
} |
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
108 |
|
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
109 |
diffViewer.show(); |
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
110 |
}, |
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
111 |
|
|
e1e14766f608
adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
146
diff
changeset
|
112 |
|
|
146
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
113 |
hightlightSource: function (source) {
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
114 |
source.className += "highlight"; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
115 |
}, |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
116 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
117 |
save: function () {
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
118 |
alert("this is it ... ");
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
119 |
} |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
120 |
} |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
121 |
} |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
122 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
123 |
</script> |