Skip to content

Instantly share code, notes, and snippets.

@robwormald
Created January 31, 2014 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robwormald/8722803 to your computer and use it in GitHub Desktop.
Save robwormald/8722803 to your computer and use it in GitHub Desktop.
angular.module('BBPlnkr').factory 'Widget', ($templateCache, Restangular) ->
_baseWidgets
_baseWidgets = Restangular.all('api/widgets')
widget = {
name: 'someWidget' #This needs to fuck off
}
#Added extra param to saveWidget
saveWidget: (snippets, fileName) ->
//or whatever
widget.file_name = fileName
for snippet in snippets
delete snippet.edited_body
widget.snippets_attributes = snippets
w = _baseWidgets.post widget
w
@davidpatters0n
Copy link

$scope.generateURL = () ->
        Widget.saveWidget($scope.snippets, $scope.file_name, $scope.widget.file_name).then (newWidget) ->
          $scope.currentWidget = newWidget
          $scope.widget.file_name
          $scope.currentWidget.file_name = newWidget.name
          $scope.setIds(newWidget)
          Widget.name = newWidget.name
          Widget.url = newWidget.url
          $window.location.hash = (newWidget.url)


Factory

 saveWidget: (snippets, fileName) ->
    widget.file_name = fileName
    for snippet in snippets
      delete snippet.edited_body
    widget.snippets_attributes = snippets
    w = _baseWidgets.post widget
    w
<a href="#" editable-text="widget.file_name">{{ widget.file_name|| 'Set File Name' }}</a>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment