diff options
| author | mo <mokha@cisco.com> | 2017-09-02 15:53:55 -0600 |
|---|---|---|
| committer | mo <mokha@cisco.com> | 2017-09-02 15:53:55 -0600 |
| commit | 69a79609d7dacf25682ed3d899bbc4ea57502401 (patch) | |
| tree | 6eab23b03c86554cc74821ca7a462d483c20795f /app/assets/javascripts/views/my/tutorials | |
| parent | 3512ca46969571a629602a26ed997ae837574ad8 (diff) | |
move bonebone code for my/* to my/* namespace.
Diffstat (limited to 'app/assets/javascripts/views/my/tutorials')
5 files changed, 93 insertions, 0 deletions
diff --git a/app/assets/javascripts/views/my/tutorials/index_view.js.coffee b/app/assets/javascripts/views/my/tutorials/index_view.js.coffee new file mode 100644 index 00000000..83692962 --- /dev/null +++ b/app/assets/javascripts/views/my/tutorials/index_view.js.coffee @@ -0,0 +1,8 @@ +#= require views/my/tutorials/no_tutorials_view +#= require views/my/tutorials/tutorial_view + +class CakeSide.Views.My.Tutorials.IndexView extends Marionette.CollectionView + childView: CakeSide.Views.My.Tutorials.TutorialView + emptyView: CakeSide.Views.My.Tutorials.NoTutorialsView + className: '' + tagName: 'div' diff --git a/app/assets/javascripts/views/my/tutorials/new_view.js.coffee b/app/assets/javascripts/views/my/tutorials/new_view.js.coffee new file mode 100644 index 00000000..4c915fc7 --- /dev/null +++ b/app/assets/javascripts/views/my/tutorials/new_view.js.coffee @@ -0,0 +1,69 @@ +#= require service/embedly_service + +class CakeSide.Views.My.Tutorials.NewView extends Marionette.ItemView + template: JST['templates/my/tutorials/new'] + ui: + url: '#tutorial_url' + url_group: '#url-group' + save_button: '#save-button' + preview: '#preview-panel' + tags: '#tutorial_tags' + + modelEvents: + 'invalid': 'displayError' + 'change:url': 'render' + + events: + 'change #tutorial_url': 'loadUrl' + "submit #new-tutorial": "save" + + initialize: -> + @model = new @collection.model() + @service = new CakeSide.EmbedlyService() + + loadUrl: -> + if @model.isValidUrl(@ui.url.val()) + @service.retrieve_info_on(@ui.url.val(), @updateTutorial) + @validate() + + updateTutorial: (attributes) => + @model.set + url: attributes.url + heading: attributes.title + description: attributes.description + image_url: if _.any(attributes.images) then attributes.images[0].url else '' + author: attributes.provider_name + author_url: attributes.provider_url + + onRender: -> + @ui.tags.tagit({ availableTags: ALL_TAGS }) + + validate: -> + @model.isValid() + + displayError: (model, error) -> + @ui.save_button.attr('disabled', 'disabled') + @ui.preview.hide() + @ui.url_group.addClass("error") + errorTag = $('<span>').addClass('help-inline').text(error) + @ui.url_group.find('.controls').append(errorTag) + + save: (event) -> + event.preventDefault() + event.stopPropagation() + @model.set('tags', @ui.tags.val()) + @ui.save_button.attr('disabled', 'disabled') + @collection.create(@model, + success: @savedSuccessfully + error: @couldNotSave + ) + + savedSuccessfully: (cake) => + window.location.hash = "tutorials" + + couldNotSave: (cake, xhr) => + @ui.save_button.removeAttr('disabled') + error = new CakeSide.Views.ErrorView + el: @$('form#new-tutorial'), + attributesWithErrors: $.parseJSON(xhr.responseText) + error.render() diff --git a/app/assets/javascripts/views/my/tutorials/no_tutorials_view.js.coffee b/app/assets/javascripts/views/my/tutorials/no_tutorials_view.js.coffee new file mode 100644 index 00000000..9b2cf3c5 --- /dev/null +++ b/app/assets/javascripts/views/my/tutorials/no_tutorials_view.js.coffee @@ -0,0 +1,3 @@ +class CakeSide.Views.My.Tutorials.NoTutorialsView extends Marionette.ItemView + template: JST['templates/my/tutorials/no_tutorials'] + tagName: 'li' diff --git a/app/assets/javascripts/views/my/tutorials/show_view.js.coffee b/app/assets/javascripts/views/my/tutorials/show_view.js.coffee new file mode 100644 index 00000000..8ea4a484 --- /dev/null +++ b/app/assets/javascripts/views/my/tutorials/show_view.js.coffee @@ -0,0 +1,5 @@ +class CakeSide.Views.My.Tutorials.ShowView extends Marionette.ItemView + template: JST["templates/my/tutorials/show"] + templateHelpers: + displayDate: (date) -> + date diff --git a/app/assets/javascripts/views/my/tutorials/tutorial_view.js.coffee b/app/assets/javascripts/views/my/tutorials/tutorial_view.js.coffee new file mode 100644 index 00000000..99631ba2 --- /dev/null +++ b/app/assets/javascripts/views/my/tutorials/tutorial_view.js.coffee @@ -0,0 +1,8 @@ +class CakeSide.Views.My.Tutorials.TutorialView extends Marionette.ItemView + template: JST['templates/my/tutorials/tutorial'] + tagName: 'div' + className: 'media' + + templateHelpers: + displayDate: (date) -> + new Date(date).toLocaleDateString() |
