5.0.0 • Published 10 years ago

ccnq-ko-rule-entry v5.0.0

Weekly downloads
1
License
Unlicense (http:/...
Repository
-
Last release
10 years ago

A Knockout Widget for CCNQ(4) rule entry

This Knockout component manages a single rule entry as stored in a CCNQ4 ruleset database. The layout of the record is adapted to the tough-rate LCR routing engine.

module.exports = (require 'kow') 'rule-entry', (ko) ->

Data

  @data class RuleEntry
    constructor: (@doc) ->
      assert @doc?, 'doc is required'
      assert @doc?.prefix?, 'doc.prefix is required'
      assert @doc?.attrs?.cdr?, 'doc.attrs.cdr is required'

      @prefix = @doc.prefix
      @cdr = ko.observable @doc.attrs.cdr
      @gwlist = new RuleGwlist @doc.gwlist
      return

We also provide the original document so that any other (extra) field is kept.

    update_doc: ->
      @doc._id = "rule:#{@prefix}"
      @doc.type = 'rule'
      @doc.prefix = @prefix
      @doc.gwlist = @gwlist.toJS()
      @doc.attrs ?= {}
      @doc.attrs.cdr = @cdr()
      @doc

Model

  @view ({value,$root,ko}) ->
    # assert value instanceof RuleEntry, 'value should be an instance of RuleEntry'
    assert value?, 'value is required'
    {ruleset_db} = $root
    assert ruleset_db?, 'ruleset_db is required'

    @notify = ko.observable ''

    @save = =>
      doc = value.update_doc()

      @notify "Saving... (#{doc._rev})"

Save the record.

      ruleset_db.put doc
      .then ({rev}) =>
        doc._rev = rev
        @notify 'Saved...'
      .catch (error) =>
        @notify "Not saved: #{error} on #{JSON.stringify doc}"

    return

Layout

  @html ({p,div,text,label,input,datalist,option,ul,li,button,tag}) ->

    div ->
      p "Add a new prefix (routing)"
      label 'Prefix: '
      input
        type:'tel'
        bind:
          value: 'prefix'
        readonly:true
        required:true
      label 'Billing: '
      input
        bind:
          value: 'cdr'
        readonly:true
        required:true
    div ->
      text 'Targets: '
      rule_gwlist 'gwlist'
      button bind: click: 'save', 'Save'
    div '.log', bind: text: 'notify', '(log)'

Extend Knockout witht the rule-gwlist component/tag.

  {RuleGwlist,rule_gwlist} = (require 'ccnq-ko-rule-gwlist') ko

assert = require 'assert'
5.0.0

10 years ago

4.4.1

10 years ago

4.4.0

10 years ago

4.3.1

10 years ago

4.3.0

10 years ago

4.2.5

10 years ago

4.2.4

10 years ago

4.2.3

10 years ago

4.2.2

10 years ago

4.2.1

10 years ago

4.2.0

10 years ago

4.1.5

10 years ago

4.1.4

10 years ago

4.1.3

10 years ago

4.1.2

10 years ago

4.1.1

10 years ago

4.1.0

10 years ago

4.0.2

10 years ago

4.0.1

10 years ago

4.0.0

10 years ago

3.0.0

10 years ago

2.2.3

10 years ago

2.2.2

10 years ago

2.2.1

10 years ago

2.2.0

10 years ago

2.1.4

10 years ago

2.1.3

10 years ago

2.1.2

10 years ago

2.1.1

10 years ago

2.1.0

10 years ago

2.0.2

10 years ago

2.0.1

10 years ago

2.0.0

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago