3.0.4 • Published 8 years ago

koco-content-management v3.0.4

Weekly downloads
1
License
MIT
Repository
-
Last release
8 years ago

koco-content-management

koco content management is a component used to create listing and editing pages for content management systems (CMS). It is an opinionated component based on the koco generator.

Table of contents

Installation

bower install koco-content-management --save

Creating a content listing page

About content listing page

//TODO

Setup

Activator for content listing page (optional)

You can use the default activator (see koco-router activator contract for more information) by first adding this to your require.config.js file

paths: {
  ...
  'content-list-page-base-activator': 'bower_components/koco-content-management/src/listing/content-list-page-base-activator'
  ...
}

and then creating an activator that inherits from the content-list-page-base-activator

define(['./my-list-page-viewmodel', 'content-list-page-base-activator'],
    function(MyEditPageViewModel, ContentEditPageBaseActivator) {
        'use strict';

        var Activator = function() {
            var self = this;

            ContentEditPageBaseActivator.call(self, new MyEditPageViewModel());
        };

        Activator.prototype = Object.create(ContentEditPageBaseActivator.prototype);
        Activator.prototype.constructor = Activator;

        return Activator;
    });

Base ViewModel for content listing page

paths: {
  ...
  'content-list-page-base-viewmodel': 'bower_components/koco-content-management/src/listing/content-list-page-base-viewmodel'
  ...
}
  • Create a shareable viewmodel that is different than the main viewmodel -ui.js (the shareable viewmodel will be joined with the main viewmodel after the activation process). This shareable viewmodel should extend (see jQuery extend for more information) the base viewmodel (content-list-page-base-viewmodel) like this:

my-list-page-viewmodel.js -->

define(['knockout', 'jquery', 'content-list-page-base-viewmodel', 'my-rest-api'],
    function(ko, $, ContentEditPageBaseViewModel, myRestApi) {
        'use strict';

        //For example
        var defaultSearchFields = {
            keywords: ''
        };

        var MyEditPageViewModel = function() {
            var contentEditPageBaseViewModel = new ContentEditPageBaseViewModel(myRestApi, 'myRestApiResource', defaultSearchFields);
            $.extend(contentEditPageBaseViewModel, this);
            var self = contentEditPageBaseViewModel;

            return self;
        };

        return MyEditPageViewModel;
    });
  • Create the main viewmodel for your content listing page. The main viewmodel will receive the shareable viewmodel as the context argument:

my-list-page-ui.js -->

define(['knockout', 'jquery', 'text!./my-list-page.html'],
    function(ko, $, template) {
        'use strict';

        var MyEditPageViewModel = function(context, componentInfo) {
            var self = this;

            $.extend(context, self);
            self = context;

            return self;
        };

        return {
            viewModel: {
                createViewModel: function(context, componentInfo) {
                    var viewmodel = new MyEditPageViewModel(context, componentInfo);

                    return viewmodel;
                }
            },
            template: template
        };
    });

Creating a content editing page

About content editing page

//TODO

Setup of content editing page

Activator for content editing page (optional)

You can use the default activator (see koco-router activator contract for more information) by first adding this to your require.config.js file

paths: {
  ...
  'content-edit-page-base-activator': 'bower_components/koco-content-management/src/listing/content-edit-page-base-activator'
  ...
}

and then creating an activator that inherits from the content-edit-page-base-activator

define(['./my-edit-page-viewmodel', 'content-edit-page-base-activator'],
    function(MyEditPageViewModel, ContentEditPageBaseActivator) {
        'use strict';

        var Activator = function() {
            var self = this;

            ContentEditPageBaseActivator.call(self, new MyEditPageViewModel());
        };

        Activator.prototype = Object.create(ContentEditPageBaseActivator.prototype);
        Activator.prototype.constructor = Activator;

        return Activator;
    });

Base ViewModel for content editing page

paths: {
  ...
  'content-edit-page-base-viewmodel': 'bower_components/koco-content-management/src/editing/content-edit-page-base-viewmodel'
  ...
}
  • Create a shareable viewmodel that is different than the main viewmodel -ui.js (the shareable viewmodel will be joined with the main viewmodel after the activation process). This shareable viewmodel should extend (see jQuery extend for more information) the base viewmodel (content-edit-page-base-viewmodel) like this:

my-edit-page-viewmodel.js -->

define(['knockout', 'jquery', 'content-edit-page-base-viewmodel', 'my-rest-api'],
    function(ko, $, ContentEditPageBaseViewModel, myRestApi) {
        'use strict';

        //For example
        self.defaultContent = {
            id: null,
            title: ''
        };

        var MyEditPageViewModel = function() {
            var contentEditPageBaseViewModel = new ContentEditPageBaseViewModel(myRestApi, 'myRestApiResource', ko.mapping.fromJS(self.defaultContent));
            $.extend(contentEditPageBaseViewModel, this);
            var self = contentEditPageBaseViewModel;

            return self;
        };

        return MyEditPageViewModel;
    });
  • Create the main viewmodel for your content editing page. The main viewmodel will receive the shareable viewmodel as the context argument:

my-edit-page-ui.js -->

define(['knockout', 'jquery', 'text!./my-edit-page.html'],
    function(ko, $, template) {
        'use strict';

        var MyEditPageViewModel = function(context, componentInfo) {
            var self = this;

            $.extend(context, self);
            self = context;

            return self;
        };

        return {
            viewModel: {
                createViewModel: function(context, componentInfo) {
                    var viewmodel = new MyEditPageViewModel(context, componentInfo);

                    return viewmodel;
                }
            },
            template: template
        };
    });

Registering Content Pages

The content management comes with a utility function that works well with koco and can be used this way:

// require.config.js
paths: {
    ...
    'content-management': 'bower_components/koco-content-management/src/content-management'
    ...
}
// components.js
define([..., 'content-management'], 
    function(contentManagement) {
        ...
        contentManagement.registerContentPages('my-content', {
                withActivator: true, //default:true
                editTitle: 'Editing My Content',
                listTitle: 'Listing My Content',
                listContentName: '' //default:adds an 's' at the end of the provided content name
            })
        ...
        });
3.0.4

8 years ago

3.1.3

8 years ago

3.1.0

9 years ago

3.0.3

9 years ago

3.0.2

9 years ago

3.0.1

9 years ago

3.0.0

9 years ago

2.4.0

9 years ago

2.3.0

9 years ago

2.0.2

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.7.23

9 years ago

1.7.22

9 years ago

1.7.21

9 years ago

1.7.20

9 years ago

1.7.19

9 years ago

1.7.18

9 years ago

1.7.17

9 years ago

1.7.16

9 years ago

1.7.15

9 years ago

1.7.14

9 years ago

1.7.8

10 years ago

1.7.7

10 years ago

1.7.6

10 years ago

1.7.5

10 years ago

1.7.4

10 years ago

1.7.3

10 years ago

1.7.2

10 years ago

1.7.1

10 years ago

1.6.1

10 years ago

1.7.0

10 years ago

1.6.0

10 years ago

1.5.0

10 years ago

1.4.0

10 years ago

1.3.1

10 years ago

1.3.0

10 years ago

1.2.1

10 years ago

1.2.0

10 years ago

1.1.0

10 years ago

1.0.0

10 years ago