Step toward a one-page application
[vchess.git] / public / javascripts / components / problemSummary.js
index 5f0fd44..54602e0 100644 (file)
@@ -1,6 +1,6 @@
-// Show a problem summary on variant page or new problem preview
+// Preview a problem on variant page
 Vue.component('my-problem-summary', {
-       props: ['prob','preview'],
+       props: ['prob','userid','preview'],
        template: `
                <div class="row problem">
                        <div class="col-sm-12 col-md-6 diagram"
@@ -8,16 +8,17 @@ Vue.component('my-problem-summary', {
                        </div>
                        <div class="col-sm-12 col-md-6">
                                <p v-html="prob.instructions"></p>
-                               <p v-if="preview" v-html="prob.solution"></p>
+                               <p v-if="!!prob.preview" v-html="prob.solution"></p>
                                <p v-else class="problem-time">{{ timestamp2date(prob.added) }}</p>
-                               <button v-if="!preview" @click="showProblem()">{{ translate("Solve") }}</button>
+                               <button v-show="!preview" @click="$emit('show-problem')">Show</button>
+                               <div v-show="prob.uid==userid && !preview" class="button-group">
+                                       <button @click="$emit('edit-problem')">Edit</button>
+                                       <button @click="$emit('delete-problem')">Delete</button>
+                               </div>
                        </div>
                </div>
        `,
        methods: {
-               translate: function(text) {
-                       return translations[text];
-               },
                getDiagram: function(fen) {
                        const fenParsed = V.ParseFen(fen);
                        return getDiagram({
@@ -29,9 +30,5 @@ Vue.component('my-problem-summary', {
                timestamp2date(ts) {
                        return getDate(new Date(ts));
                },
-               // Propagate "show problem" event to parent component (my-problems)
-               showProblem: function() {
-                       this.$emit('show-problem');
-               },
        },
 })