/**
 * @license
 * Copyright 2020 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */
foam.CLASS({
  package: 'foam.nanos.crunch.ui',
  name: 'CapabilityWizardlet',
  extends: 'foam.u2.wizard.BaseWizardlet',

  implements: [
    'foam.mlang.Expressions'
  ],

  imports: [
    'crunchController',
    'localeDAO'
  ],

  properties: [
    // Properties specific to CapabilityWizardSection
    {
      name: 'capability'
    },
    {
      name: 'ucj'
    },
    {
      name: 'id',
      expression: function (capability) {
        return 'capability,' + capability.id;
      }
    },

    // Properties for WizardSection interface
    {
      name: 'of',
      class: 'Class',
      expression: function(capability) {
        if ( ! capability || ! capability.of ) return null;
        return capability.of;
      }
    },
    {
      name: 'data',
      flags: ['web'],
      factory: function() {
        if ( ! this.of ) return null;

        var ret = this.of.getAxiomByName('capability') ?
          this.of.create({ capability: this.capability }, this) :
          this.of.create({}, this);

        if ( this.ucj === null ) return ret;

        ret = Object.assign(ret, this.ucj.data);
        return ret;
      }
    },
    {
      name: 'title',
      class: 'String',
      expression: function(capability) {
        if ( ! capability || ! capability.name ) return '';
        return capability.name;
      }
    }
  ],

  methods: [
    {
      name: 'save',
      code: function() {
        return this.crunchController && this.crunchController.save(this);
      }
    }
  ]
});

@@ -999,38 +999,25 @@
 .of.
-getAxiomByName('capability') ?
+create(%7B%7D, this);
 %0A   
@@ -1025,103 +1025,128 @@
     
- 
+if (
  this.
-of.create(%7B capability: this.capability %7D, this) :%0A          this.of.create(%7B%7D, this
+ucj && this.ucj.data ) ret.copyFrom(this.ucj.data);%0A%0A        var prop = this.of.getAxiomByName('capability'
 );%0A
-%0A
     
@@ -1158,68 +1158,23 @@
 f ( 
-this.ucj === null ) return ret;%0A%0A        ret = Object.assign
+prop ) prop.set
 (ret
@@ -1180,27 +1180,30 @@
 t, this.
-ucj.data
+capability
 );%0A
+%0A
         

Fix retaining capability for document