Sha256: d3b32f65174a39e3d6e361bd3a32344d2088b804fd5ee74c2daf03fb2879ab8d

Contents?: true

Size: 1.75 KB

Versions: 30

Compression:

Stored size: 1.75 KB

Contents

angular.module 'NgCreate', ['Factories', 'FactoryName']

  .directive 'ngCreate', ($injector, factoryName) ->
    restrict: 'A'
    require: '?ngCallback'
    link: (scope, element, attributes, ngCallbackCtrl) ->
      element.bind 'click', (event) ->
        [parentName, listName] = attributes.ngContext.split('.') if attributes.ngContext
        attr = scope.$eval('(' + attributes.ngAttributes + ')') || {}
        create(attributes.ngCreate,parentName,listName,attr)
      create = (modelName,parentName,listName,attributes) ->
        addTo = element[0].attributes['ng-add-to'].value if element[0].attributes['ng-add-to']
        factory = factoryName(modelName)
        list = $injector.get(factory)
        object = {}
        object[modelName] = attributes
        if parentName
          object[modelName][parentName]         = scope[parentName]    unless parentName.indexOf('_id') < 0
          object[modelName][parentName + '_id'] = scope[parentName].id     if parentName.indexOf('_id') < 0
          object[parentName]                    = scope[parentName]    unless parentName.indexOf('_id') < 0
          object[parentName + '_id']            = scope[parentName].id     if parentName.indexOf('_id') < 0
        list.create object, (returnData) ->
          if addTo
            scope[addTo].push(returnData)
          if listName
            scope = if scope[parentName] then scope else scope.$parent
            scope[parentName] = {} unless scope[parentName]
            scope[parentName][listName] = [] unless scope[parentName][listName]
            scope[parentName][listName].push(returnData)
          else
            scope[factory] = [] unless scope[factory]
            scope[factory].push(returnData)
          ngCallbackCtrl.evaluate(returnData) if !!ngCallbackCtrl

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
material_raingular-0.1.3.5 lib/assets/javascripts/directives/ngcreate.js.coffee
material_raingular-0.1.3 lib/assets/javascripts/directives/ngcreate.js.coffee
material_raingular-0.1.2 lib/assets/javascripts/directives/ngcreate.js.coffee
material_raingular-0.1.1 lib/assets/javascripts/directives/ngcreate.js.coffee
material_raingular-0.1.0 lib/assets/javascripts/directives/ngcreate.js.coffee
material_raingular-0.0.7 lib/assets/javascripts/directives/ngcreate.js.coffee
material_raingular-0.0.6 lib/assets/javascripts/directives/ngcreate.js.coffee
material_raingular-0.0.5 lib/assets/javascripts/directives/ngcreate.js.coffee
material_raingular-0.0.4.3 lib/assets/javascripts/directives/ngcreate.js.coffee
material_raingular-0.0.4.2.1 lib/assets/javascripts/directives/ngcreate.js.coffee
material_raingular-0.0.4.2 lib/assets/javascripts/directives/ngcreate.js.coffee
material_raingular-0.0.4.1.1 lib/assets/javascripts/directives/ngcreate.js.coffee
material_raingular-0.0.4.1 lib/assets/javascripts/directives/ngcreate.js.coffee
material_raingular-0.0.4.0 lib/assets/javascripts/directives/ngcreate.js.coffee
material_raingular-0.0.3.9 lib/assets/javascripts/directives/ngcreate.js.coffee
material_raingular-0.0.3.8 lib/assets/javascripts/directives/ngcreate.js.coffee
material_raingular-0.0.3.7 lib/assets/javascripts/directives/ngcreate.js.coffee
material_raingular-0.0.3.6 lib/assets/javascripts/directives/ngcreate.js.coffee
material_raingular-0.0.3.5 lib/assets/javascripts/directives/ngcreate.js.coffee
material_raingular-0.0.3.4 lib/assets/javascripts/directives/ngcreate.js.coffee