Sha256: 9b036b7f789f85b1d612bc3aad7553ebc42863f8f14ab4ed6431f8284dfd890c

Contents?: true

Size: 1.72 KB

Versions: 13

Compression:

Stored size: 1.72 KB

Contents

import Vue from 'vue';
import moment from 'moment';

export default Vue.component('node-form', {

  props: {
    node: {
      coerce: (val) => JSON.parse(val)
    }
  },

  computed: {
    humanizedType: function() {
      return this.node.type.replace( /([A-Z])/g, (m) => ` ${ m.toLowerCase() }` ).trim();
    },

    isPublished: function() {
      return this.node.status === 'published';
    },

    saveButtonText: function() {
      switch(this.node.status) {
        case 'draft':
          if (this.node['new_record?'] || !this.node.published_at) {
            return 'Save draft';
          } else {
            return `Unpublish ${ this.humanizedType }`;
          }
        case 'published':
          if (this.node['new_record?'] || !this.node.published_at) {
            return this.publishedAtMoment.toDate() > new Date() ? 'Publish later' : 'Publish now';
          } else {
            return `Save ${ this.humanizedType }`;
          }
      }
    },

    publishedAtMoment: function() {
      return this.node.published_at ? moment(this.node.published_at) : moment();
    },

    publishedDates: function() {
      switch(this.node.status) {
        case 'draft':
          return 'N/A';
        case 'published':
          if (this.node['new_record?'] || !this.node.published_at) {
            return this.publishedAtMoment.toDate() > new Date() ? this.publishedAtMoment.format('Do MMM YYYY, h:mma') : 'Immediately';
          } else {
            return this.publishedAtMoment.format('Do MMM YYYY, h:mma');
          }
      }
    }
  },

  methods: {
    setSlug: function() {
      if (this.node['new_record?']) {
        this.node.slug = this.node.title.toLowerCase().replace(/[\s\_]/g, '-').replace(/[^\w\-]/g, '');
      }
    }
  }
  
})

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
push_type_admin-0.9.3 app/webpack/javascripts/components/node-form.es6
push_type_admin-0.9.2 app/webpack/javascripts/components/node-form.es6
push_type_admin-0.9.1 app/webpack/javascripts/components/node-form.es6
push_type_admin-0.9.0 app/webpack/javascripts/components/node-form.es6
push_type_admin-0.9.0.beta.4 app/webpack/javascripts/components/node-form.es6
push_type_admin-0.9.0.beta.3 app/webpack/javascripts/components/node-form.es6
push_type_admin-0.9.0.beta.2 app/webpack/javascripts/components/node-form.es6
push_type_admin-0.8.2 app/webpack/javascripts/components/node-form.es6
push_type_admin-0.8.1 app/webpack/javascripts/components/node-form.es6
push_type_admin-0.8.0 app/webpack/javascripts/components/node-form.es6
push_type_admin-0.8.0.beta.3 app/webpack/javascripts/components/node-form.es6
push_type_admin-0.8.0.beta.2 app/webpack/javascripts/components/node-form.es6
push_type_admin-0.8.0.beta.1 app/webpack/javascripts/components/node-form.es6