From 91b9c5c2c43e328e60dbb4d8aace02566c65dd2b Mon Sep 17 00:00:00 2001 From: bnwest Date: Wed, 25 Sep 2013 02:57:18 +0200 Subject: [PATCH 01/14] stub --- scripts/gh-book/gdoc-xhtml-file.coffee | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 scripts/gh-book/gdoc-xhtml-file.coffee diff --git a/scripts/gh-book/gdoc-xhtml-file.coffee b/scripts/gh-book/gdoc-xhtml-file.coffee new file mode 100644 index 00000000..a0392f0f --- /dev/null +++ b/scripts/gh-book/gdoc-xhtml-file.coffee @@ -0,0 +1,22 @@ +define [ + 'underscore' + 'jquery' + 'backbone' + 'cs!models/content/module' + 'cs!gh-book/xhtml-file' +], (_, $, Backbone, ModuleModel, XhtmlModel) -> + + # The `Content` model contains the following members: + # + # * `title` - an HTML title of the content + # * `language` - the main language (eg `en-us`) + # * `subjects` - an array of strings (eg `['Mathematics', 'Business']`) + # * `keywords` - an array of keywords (eg `['constant', 'boltzmann constant']`) + # * `authors` - an `Collection` of `User`s that are attributed as authors + return class GoogleDocXhtmlModel extends XhtmlModel + mediaType: 'application/xhtml+gdoc' + + title: 'Google Document Import' + + _loadComplex = (promise) -> + return promise From acbb620b739e0f6e11bdc253f2b7d3ac59971ed1 Mon Sep 17 00:00:00 2001 From: bnwest Date: Wed, 25 Sep 2013 21:44:56 +0200 Subject: [PATCH 02/14] first attempt to get gdoc importer into the Add drop down --- scripts/gh-book/app.coffee | 4 +++- scripts/gh-book/gdoc-xhtml-file.coffee | 4 +++- scripts/gh-book/opf-file.coffee | 5 +++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/gh-book/app.coffee b/scripts/gh-book/app.coffee index abe232b6..3d53936b 100644 --- a/scripts/gh-book/app.coffee +++ b/scripts/gh-book/app.coffee @@ -9,6 +9,7 @@ define [ 'cs!collections/media-types' 'cs!gh-book/epub-container' 'cs!gh-book/xhtml-file' + 'cs!gh-book/gdoc-xhtml-file' 'cs!gh-book/opf-file' 'cs!gh-book/toc-node' 'cs!gh-book/binary-file' @@ -18,7 +19,7 @@ define [ 'cs!configs/github.coffee' 'less!styles/main' 'less!gh-book/gh-book' -], ($, _, Backbone, Marionette, logger, session, allContent, mediaTypes, EpubContainer, XhtmlFile, OpfFile, TocNode, BinaryFile, WelcomeSignInView, remoteUpdater, LoadingView, config) -> +], ($, _, Backbone, Marionette, logger, session, allContent, mediaTypes, EpubContainer, XhtmlFile, GoogleDocXhtmlFile, OpfFile, TocNode, BinaryFile, WelcomeSignInView, remoteUpdater, LoadingView, config) -> # Stop logging. logger.stop() @@ -93,6 +94,7 @@ define [ mediaTypes.add TocNode mediaTypes.add BinaryFile, {mediaType:'image/png'} mediaTypes.add BinaryFile, {mediaType:'image/jpeg'} + mediaTypes.add GoogleDocXhtmlFile, {mediaType:GoogleDocXhtmlFile::uniqueMediaType} # Views use anchors with hrefs so catch the click and send it to Backbone diff --git a/scripts/gh-book/gdoc-xhtml-file.coffee b/scripts/gh-book/gdoc-xhtml-file.coffee index a0392f0f..0d7e2019 100644 --- a/scripts/gh-book/gdoc-xhtml-file.coffee +++ b/scripts/gh-book/gdoc-xhtml-file.coffee @@ -14,7 +14,9 @@ define [ # * `keywords` - an array of keywords (eg `['constant', 'boltzmann constant']`) # * `authors` - an `Collection` of `User`s that are attributed as authors return class GoogleDocXhtmlModel extends XhtmlModel - mediaType: 'application/xhtml+gdoc' + mediaType: 'application/xhtml+xml' + + uniqueMediaType: 'application/vnd.org.cnx.gdoc-import' title: 'Google Document Import' diff --git a/scripts/gh-book/opf-file.coffee b/scripts/gh-book/opf-file.coffee index bc2faee8..e4bbcd57 100644 --- a/scripts/gh-book/opf-file.coffee +++ b/scripts/gh-book/opf-file.coffee @@ -4,10 +4,11 @@ define [ 'cs!collections/content' 'cs!mixins/loadable' 'cs!gh-book/xhtml-file' + 'cs!gh-book/gdoc-xhtml-file' 'cs!gh-book/toc-node' 'cs!gh-book/toc-pointer-node' 'cs!gh-book/utils' -], (Backbone, mediaTypes, allContent, loadable, XhtmlFile, TocNode, TocPointerNode, Utils) -> +], (Backbone, mediaTypes, allContent, loadable, XhtmlFile, GoogleDocXhtmlFile, TocNode, TocPointerNode, Utils) -> SAVE_DELAY = 10 # ms @@ -16,7 +17,7 @@ define [ serializer = new XMLSerializer() mediaType: 'application/oebps-package+xml' - accept: [XhtmlFile::mediaType, TocNode::mediaType] + accept: [XhtmlFile::mediaType, TocNode::mediaType, GoogleDocXhtmlFile::uniqueMediaType] branch: true # This element will show up in the sidebar listing From 8c5d19d28b3cc9211110b2ce94c597153335d6e0 Mon Sep 17 00:00:00 2001 From: bnwest Date: Fri, 27 Sep 2013 14:07:02 +0200 Subject: [PATCH 03/14] stype google doc import drop down item --- scripts/gh-book/gh-book.less | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/gh-book/gh-book.less b/scripts/gh-book/gh-book.less index f8da7fe9..b7f431c9 100755 --- a/scripts/gh-book/gh-book.less +++ b/scripts/gh-book/gh-book.less @@ -5,9 +5,10 @@ @{mt-selector} > .add-content-title::before { content: "New " @add-title; color: black; } } -.x-media-type-icon('application/xhtml+xml'; "Content"; #00c; "\f0f6"); /* icon-file-alt */ -.x-media-type-icon('application/oebps-package+xml'; "Book"; #c00; "\f02d"); /* icon-book */ -.x-media-type-icon('application/vnd.org.cnx.section'; "Chapter"; #999; ""); /* icon-folder-open */ +.x-media-type-icon('application/xhtml+xml'; "Content"; #00c; "\f0f6"); /* icon-file-alt */ +.x-media-type-icon('application/oebps-package+xml'; "Book"; #c00; "\f02d"); /* icon-book */ +.x-media-type-icon('application/vnd.org.cnx.section'; "Chapter"; #999; ""); /* icon-folder-open */ +.x-media-type-icon('application/vnd.org.cnx.gdoc-import'; "Google Doc Import"; #999; "\f0d5"); /* icon-google-plus */ // Hide the "Add Book" dropdown from the workspace From 4a442929d59232ae0ea23bdd2111a7929eb6e376 Mon Sep 17 00:00:00 2001 From: bnwest Date: Fri, 27 Sep 2013 19:00:12 +0200 Subject: [PATCH 04/14] namespace-ified google's js API --- scripts/gh-book/googlejsapi.js | 47 ++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 scripts/gh-book/googlejsapi.js diff --git a/scripts/gh-book/googlejsapi.js b/scripts/gh-book/googlejsapi.js new file mode 100644 index 00000000..d3c875b9 --- /dev/null +++ b/scripts/gh-book/googlejsapi.js @@ -0,0 +1,47 @@ +(function () { + +/* modified: http://www.google.com/jsapi e.g. ClientLocation is set to null */ + +if(!window['googleLT_']){window['googleLT_']=(new Date()).getTime();}if (!window['google']) { + window['google'] = {}; +} +if (!window['google']['loader']) { + window['google']['loader'] = {}; + google.loader.ServiceBase = 'http://www.google.com/uds'; + google.loader.GoogleApisBase = 'http://ajax.googleapis.com/ajax'; + google.loader.ApiKey = 'notsupplied'; + google.loader.KeyVerified = true; + google.loader.LoadFailure = false; + google.loader.Secure = false; + google.loader.GoogleLocale = 'www.google.com'; + google.loader.ClientLocation = null; + google.loader.AdditionalParams = ''; + (function() {var d=void 0,g=!0,h=null,j=!1,k=encodeURIComponent,l=window,m=document;function n(a,b){return a.load=b}var p="push",q="replace",r="charAt",t="indexOf",u="ServiceBase",v="name",w="getTime",x="length",y="prototype",z="setTimeout",A="loader",B="substring",C="join",D="toLowerCase";function E(a){return a in F?F[a]:F[a]=-1!=navigator.userAgent[D]()[t](a)}var F={};function G(a,b){var c=function(){};c.prototype=b[y];a.S=b[y];a.prototype=new c} + function H(a,b,c){var e=Array[y].slice.call(arguments,2)||[];return function(){var c=e.concat(Array[y].slice.call(arguments));return a.apply(b,c)}}function I(a){a=Error(a);a.toString=function(){return this.message};return a}function J(a,b){for(var c=a.split(/\./),e=l,f=0;f<\/script>"):(E("safari")||E("konqueror"))&&l[z](T,10)),P[p](a)):Q(l,"load",a)};L("google.setOnLoadCallback",google.R); + function Q(a,b,c){if(a.addEventListener)a.addEventListener(b,c,j);else if(a.attachEvent)a.attachEvent("on"+b,c);else{var e=a["on"+b];a["on"+b]=e!=h?aa([c,e]):c}}function aa(a){return function(){for(var b=0;b<\/script>'):"css"==a&&m.write('')}; + L("google.loader.writeLoadTag",google[A].d);google[A].O=function(a){O=a};L("google.loader.rfm",google[A].O);google[A].Q=function(a){for(var b in a)"string"==typeof b&&b&&":"==b[r](0)&&!N[b]&&(N[b]=new U(b[B](1),a[b]))};L("google.loader.rpl",google[A].Q);google[A].P=function(a){if((a=a.specs)&&a[x])for(var b=0;b Date: Sat, 28 Sep 2013 14:50:21 +0200 Subject: [PATCH 05/14] call gdoc2html service and get back html --- scripts/gh-book/gdoc-xhtml-file.coffee | 83 +++++++++++++++++++++++++- scripts/gh-book/googlejsapi.js | 5 -- 2 files changed, 82 insertions(+), 6 deletions(-) diff --git a/scripts/gh-book/gdoc-xhtml-file.coffee b/scripts/gh-book/gdoc-xhtml-file.coffee index 0d7e2019..2a0fbd64 100644 --- a/scripts/gh-book/gdoc-xhtml-file.coffee +++ b/scripts/gh-book/gdoc-xhtml-file.coffee @@ -4,8 +4,80 @@ define [ 'backbone' 'cs!models/content/module' 'cs!gh-book/xhtml-file' + 'gh-book/googlejsapi' ], (_, $, Backbone, ModuleModel, XhtmlModel) -> + gdocpicker_deferred = undefined + + newPicker = () -> + google.load('picker', '1', {"callback" : createPicker}) + gdocpicker_deferred = $.Deferred() + return gdocpicker_deferred.promise() + + createPicker = () -> + picker = new google.picker.PickerBuilder(). + addView(google.picker.ViewId.DOCUMENTS). + setCallback(pickerCallback). + build() + picker.setVisible(true); + return picker + + pickerCallback = (data) -> + if data.action is google.picker.Action.PICKED + gdocpicker_deferred.resolve(data) + else if data.action is google.picker.Action.CANCEL + gdocpicker_deferred.reject() + + getGoogleDocHtml = (data) -> + gdoc_resource_id = data.docs[0].id + html_url = 'https://docs.google.com/document/d/' + gdoc_resource_id + + '/export?format=html&confirm=no_antivirus' + gdoc_html_promise = $.get(html_url) + return gdoc_html_promise + + transformGoogleDocHtml = (html) -> + gdoc_transform_promise = $.ajax( + dataType: "json" + type: "POST" + async: true + url: "http://testing.oerpub.org/gdoc2html" # evetually http://remix.oerpub.org/gdoc2html + data: + html: html + textbook_html: 0 + copy_images: 0 + ) + return gdoc_transform_promise + + injectHtml = (bodyhtml) -> + # bodyhtml is "..." + @set 'body', bodyhtml + + cleanupFailedImport = () -> + return + + importGoogleDoc = () -> + # alerts need to turned into log messages or deleted + gdocpicker_promise = newPicker() + gdocpicker_promise.done (data) -> + gdoc_html_promise = getGoogleDocHtml(data) + gdoc_html_promise.done (data, status, xhr) -> + html = data + alert "got html from google" + gdoc_transform_promise = transformGoogleDocHtml(html) + gdoc_transform_promise.done (data, status, xhr) -> + alert "gdoc2html service succeeded" + bodyhtml = data["html"] + injectHtml(bodyhtml) + gdoc_transform_promise.fail (data, status, xhr) -> + alert "gdoc service failed to tranform html into aloha ready html." + cleanupFailedImport() + gdoc_html_promise.fail (data, status, xhr) -> + alert "failed to get the google doc's html from google." + cleanupFailedImport() + gdocpicker_promise.fail -> + alert "canceled out of the google doc picker." + cleanupFailedImport() + # The `Content` model contains the following members: # # * `title` - an HTML title of the content @@ -20,5 +92,14 @@ define [ title: 'Google Document Import' - _loadComplex = (promise) -> + initialize: () -> + super() + # super() does the following, so we do not + # @setNew() + # @id = "content/#{uuid()}" + + # this don't go here, _loadComplex() aint right either but closer to the mark + importGoogleDoc() + + @_loadComplex = (promise) -> return promise diff --git a/scripts/gh-book/googlejsapi.js b/scripts/gh-book/googlejsapi.js index d3c875b9..bba2e004 100644 --- a/scripts/gh-book/googlejsapi.js +++ b/scripts/gh-book/googlejsapi.js @@ -1,5 +1,3 @@ -(function () { - /* modified: http://www.google.com/jsapi e.g. ClientLocation is set to null */ if(!window['googleLT_']){window['googleLT_']=(new Date()).getTime();}if (!window['google']) { @@ -42,6 +40,3 @@ if (!window['google']['loader']) { google.loader.rpl({":scriptaculous":{"versions":{":1.8.3":{"uncompressed":"scriptaculous.js","compressed":"scriptaculous.js"},":1.9.0":{"uncompressed":"scriptaculous.js","compressed":"scriptaculous.js"},":1.8.2":{"uncompressed":"scriptaculous.js","compressed":"scriptaculous.js"},":1.8.1":{"uncompressed":"scriptaculous.js","compressed":"scriptaculous.js"}},"aliases":{":1.8":"1.8.3",":1":"1.9.0",":1.9":"1.9.0"}},":yui":{"versions":{":2.6.0":{"uncompressed":"build/yuiloader/yuiloader.js","compressed":"build/yuiloader/yuiloader-min.js"},":2.9.0":{"uncompressed":"build/yuiloader/yuiloader.js","compressed":"build/yuiloader/yuiloader-min.js"},":2.7.0":{"uncompressed":"build/yuiloader/yuiloader.js","compressed":"build/yuiloader/yuiloader-min.js"},":2.8.0r4":{"uncompressed":"build/yuiloader/yuiloader.js","compressed":"build/yuiloader/yuiloader-min.js"},":2.8.2r1":{"uncompressed":"build/yuiloader/yuiloader.js","compressed":"build/yuiloader/yuiloader-min.js"},":2.8.1":{"uncompressed":"build/yuiloader/yuiloader.js","compressed":"build/yuiloader/yuiloader-min.js"},":3.3.0":{"uncompressed":"build/yui/yui.js","compressed":"build/yui/yui-min.js"}},"aliases":{":3":"3.3.0",":2":"2.9.0",":2.7":"2.7.0",":2.8.2":"2.8.2r1",":2.6":"2.6.0",":2.9":"2.9.0",":2.8":"2.8.2r1",":2.8.0":"2.8.0r4",":3.3":"3.3.0"}},":swfobject":{"versions":{":2.1":{"uncompressed":"swfobject_src.js","compressed":"swfobject.js"},":2.2":{"uncompressed":"swfobject_src.js","compressed":"swfobject.js"}},"aliases":{":2":"2.2"}},":webfont":{"versions":{":1.0.2":{"uncompressed":"webfont_debug.js","compressed":"webfont.js"},":1.0.1":{"uncompressed":"webfont_debug.js","compressed":"webfont.js"},":1.0.0":{"uncompressed":"webfont_debug.js","compressed":"webfont.js"},":1.0.19":{"uncompressed":"webfont_debug.js","compressed":"webfont.js"},":1.0.6":{"uncompressed":"webfont_debug.js","compressed":"webfont.js"},":1.0.18":{"uncompressed":"webfont_debug.js","compressed":"webfont.js"},":1.0.5":{"uncompressed":"webfont_debug.js","compressed":"webfont.js"},":1.0.17":{"uncompressed":"webfont_debug.js","compressed":"webfont.js"},":1.0.4":{"uncompressed":"webfont_debug.js","compressed":"webfont.js"},":1.0.16":{"uncompressed":"webfont_debug.js","compressed":"webfont.js"},":1.0.3":{"uncompressed":"webfont_debug.js","compressed":"webfont.js"},":1.0.9":{"uncompressed":"webfont_debug.js","compressed":"webfont.js"},":1.0.21":{"uncompressed":"webfont_debug.js","compressed":"webfont.js"},":1.0.12":{"uncompressed":"webfont_debug.js","compressed":"webfont.js"},":1.0.22":{"uncompressed":"webfont_debug.js","compressed":"webfont.js"},":1.0.13":{"uncompressed":"webfont_debug.js","compressed":"webfont.js"},":1.0.14":{"uncompressed":"webfont_debug.js","compressed":"webfont.js"},":1.0.15":{"uncompressed":"webfont_debug.js","compressed":"webfont.js"},":1.0.23":{"uncompressed":"webfont_debug.js","compressed":"webfont.js"},":1.0.10":{"uncompressed":"webfont_debug.js","compressed":"webfont.js"},":1.0.11":{"uncompressed":"webfont_debug.js","compressed":"webfont.js"}},"aliases":{":1":"1.0.23",":1.0":"1.0.23"}},":ext-core":{"versions":{":3.1.0":{"uncompressed":"ext-core-debug.js","compressed":"ext-core.js"},":3.0.0":{"uncompressed":"ext-core-debug.js","compressed":"ext-core.js"}},"aliases":{":3":"3.1.0",":3.0":"3.0.0",":3.1":"3.1.0"}},":mootools":{"versions":{":1.2.3":{"uncompressed":"mootools.js","compressed":"mootools-yui-compressed.js"},":1.3.1":{"uncompressed":"mootools.js","compressed":"mootools-yui-compressed.js"},":1.1.1":{"uncompressed":"mootools.js","compressed":"mootools-yui-compressed.js"},":1.2.4":{"uncompressed":"mootools.js","compressed":"mootools-yui-compressed.js"},":1.3.0":{"uncompressed":"mootools.js","compressed":"mootools-yui-compressed.js"},":1.2.1":{"uncompressed":"mootools.js","compressed":"mootools-yui-compressed.js"},":1.2.2":{"uncompressed":"mootools.js","compressed":"mootools-yui-compressed.js"},":1.3.2":{"uncompressed":"mootools.js","compressed":"mootools-yui-compressed.js"},":1.2.5":{"uncompressed":"mootools.js","compressed":"mootools-yui-compressed.js"},":1.4.0":{"uncompressed":"mootools.js","compressed":"mootools-yui-compressed.js"},":1.1.2":{"uncompressed":"mootools.js","compressed":"mootools-yui-compressed.js"},":1.4.1":{"uncompressed":"mootools.js","compressed":"mootools-yui-compressed.js"}},"aliases":{":1":"1.1.2",":1.11":"1.1.1",":1.4":"1.4.1",":1.3":"1.3.2",":1.2":"1.2.5",":1.1":"1.1.2"}},":jqueryui":{"versions":{":1.6.0":{"uncompressed":"jquery-ui.js","compressed":"jquery-ui.min.js"},":1.8.0":{"uncompressed":"jquery-ui.js","compressed":"jquery-ui.min.js"},":1.8.2":{"uncompressed":"jquery-ui.js","compressed":"jquery-ui.min.js"},":1.8.1":{"uncompressed":"jquery-ui.js","compressed":"jquery-ui.min.js"},":1.8.9":{"uncompressed":"jquery-ui.js","compressed":"jquery-ui.min.js"},":1.8.15":{"uncompressed":"jquery-ui.js","compressed":"jquery-ui.min.js"},":1.8.14":{"uncompressed":"jquery-ui.js","compressed":"jquery-ui.min.js"},":1.8.7":{"uncompressed":"jquery-ui.js","compressed":"jquery-ui.min.js"},":1.8.13":{"uncompressed":"jquery-ui.js","compressed":"jquery-ui.min.js"},":1.8.8":{"uncompressed":"jquery-ui.js","compressed":"jquery-ui.min.js"},":1.8.12":{"uncompressed":"jquery-ui.js","compressed":"jquery-ui.min.js"},":1.8.11":{"uncompressed":"jquery-ui.js","compressed":"jquery-ui.min.js"},":1.7.2":{"uncompressed":"jquery-ui.js","compressed":"jquery-ui.min.js"},":1.8.5":{"uncompressed":"jquery-ui.js","compressed":"jquery-ui.min.js"},":1.7.3":{"uncompressed":"jquery-ui.js","compressed":"jquery-ui.min.js"},":1.8.10":{"uncompressed":"jquery-ui.js","compressed":"jquery-ui.min.js"},":1.8.6":{"uncompressed":"jquery-ui.js","compressed":"jquery-ui.min.js"},":1.7.0":{"uncompressed":"jquery-ui.js","compressed":"jquery-ui.min.js"},":1.7.1":{"uncompressed":"jquery-ui.js","compressed":"jquery-ui.min.js"},":1.8.4":{"uncompressed":"jquery-ui.js","compressed":"jquery-ui.min.js"},":1.5.3":{"uncompressed":"jquery-ui.js","compressed":"jquery-ui.min.js"},":1.5.2":{"uncompressed":"jquery-ui.js","compressed":"jquery-ui.min.js"},":1.8.16":{"uncompressed":"jquery-ui.js","compressed":"jquery-ui.min.js"}},"aliases":{":1.8":"1.8.16",":1.7":"1.7.3",":1.6":"1.6.0",":1":"1.8.16",":1.5":"1.5.3",":1.8.3":"1.8.4"}},":chrome-frame":{"versions":{":1.0.2":{"uncompressed":"CFInstall.js","compressed":"CFInstall.min.js"},":1.0.1":{"uncompressed":"CFInstall.js","compressed":"CFInstall.min.js"},":1.0.0":{"uncompressed":"CFInstall.js","compressed":"CFInstall.min.js"}},"aliases":{":1":"1.0.2",":1.0":"1.0.2"}},":jquery":{"versions":{":1.6.2":{"uncompressed":"jquery.js","compressed":"jquery.min.js"},":1.3.1":{"uncompressed":"jquery.js","compressed":"jquery.min.js"},":1.6.1":{"uncompressed":"jquery.js","compressed":"jquery.min.js"},":1.3.0":{"uncompressed":"jquery.js","compressed":"jquery.min.js"},":1.6.4":{"uncompressed":"jquery.js","compressed":"jquery.min.js"},":1.6.3":{"uncompressed":"jquery.js","compressed":"jquery.min.js"},":1.3.2":{"uncompressed":"jquery.js","compressed":"jquery.min.js"},":1.6.0":{"uncompressed":"jquery.js","compressed":"jquery.min.js"},":1.2.3":{"uncompressed":"jquery.js","compressed":"jquery.min.js"},":1.7.0":{"uncompressed":"jquery.js","compressed":"jquery.min.js"},":1.7.1":{"uncompressed":"jquery.js","compressed":"jquery.min.js"},":1.2.6":{"uncompressed":"jquery.js","compressed":"jquery.min.js"},":1.4.3":{"uncompressed":"jquery.js","compressed":"jquery.min.js"},":1.4.4":{"uncompressed":"jquery.js","compressed":"jquery.min.js"},":1.5.1":{"uncompressed":"jquery.js","compressed":"jquery.min.js"},":1.5.0":{"uncompressed":"jquery.js","compressed":"jquery.min.js"},":1.4.0":{"uncompressed":"jquery.js","compressed":"jquery.min.js"},":1.5.2":{"uncompressed":"jquery.js","compressed":"jquery.min.js"},":1.4.1":{"uncompressed":"jquery.js","compressed":"jquery.min.js"},":1.4.2":{"uncompressed":"jquery.js","compressed":"jquery.min.js"}},"aliases":{":1.7":"1.7.1",":1.6":"1.6.4",":1":"1.7.1",":1.5":"1.5.2",":1.4":"1.4.4",":1.3":"1.3.2",":1.2":"1.2.6"}},":prototype":{"versions":{":1.7.0.0":{"uncompressed":"prototype.js","compressed":"prototype.js"},":1.6.0.2":{"uncompressed":"prototype.js","compressed":"prototype.js"},":1.6.1.0":{"uncompressed":"prototype.js","compressed":"prototype.js"},":1.6.0.3":{"uncompressed":"prototype.js","compressed":"prototype.js"}},"aliases":{":1.7":"1.7.0.0",":1.6.1":"1.6.1.0",":1":"1.7.0.0",":1.6":"1.6.1.0",":1.7.0":"1.7.0.0",":1.6.0":"1.6.0.3"}},":dojo":{"versions":{":1.3.1":{"uncompressed":"dojo/dojo.xd.js.uncompressed.js","compressed":"dojo/dojo.xd.js"},":1.1.1":{"uncompressed":"dojo/dojo.xd.js.uncompressed.js","compressed":"dojo/dojo.xd.js"},":1.3.0":{"uncompressed":"dojo/dojo.xd.js.uncompressed.js","compressed":"dojo/dojo.xd.js"},":1.6.1":{"uncompressed":"dojo/dojo.xd.js.uncompressed.js","compressed":"dojo/dojo.xd.js"},":1.3.2":{"uncompressed":"dojo/dojo.xd.js.uncompressed.js","compressed":"dojo/dojo.xd.js"},":1.6.0":{"uncompressed":"dojo/dojo.xd.js.uncompressed.js","compressed":"dojo/dojo.xd.js"},":1.2.3":{"uncompressed":"dojo/dojo.xd.js.uncompressed.js","compressed":"dojo/dojo.xd.js"},":1.4.3":{"uncompressed":"dojo/dojo.xd.js.uncompressed.js","compressed":"dojo/dojo.xd.js"},":1.5.1":{"uncompressed":"dojo/dojo.xd.js.uncompressed.js","compressed":"dojo/dojo.xd.js"},":1.5.0":{"uncompressed":"dojo/dojo.xd.js.uncompressed.js","compressed":"dojo/dojo.xd.js"},":1.2.0":{"uncompressed":"dojo/dojo.xd.js.uncompressed.js","compressed":"dojo/dojo.xd.js"},":1.4.0":{"uncompressed":"dojo/dojo.xd.js.uncompressed.js","compressed":"dojo/dojo.xd.js"},":1.4.1":{"uncompressed":"dojo/dojo.xd.js.uncompressed.js","compressed":"dojo/dojo.xd.js"}},"aliases":{":1":"1.6.1",":1.6":"1.6.1",":1.5":"1.5.1",":1.4":"1.4.3",":1.3":"1.3.2",":1.2":"1.2.3",":1.1":"1.1.1"}}}); } -return google; -}()); - From a6aac66426e14ab3c3115817c6fe02556b8d6a99 Mon Sep 17 00:00:00 2001 From: bnwest Date: Mon, 30 Sep 2013 16:13:03 +0200 Subject: [PATCH 06/14] got _loadComplex() plumbing to work. imported html is diplayed in the editable area. woo hoo. --- scripts/gh-book/gdoc-xhtml-file.coffee | 78 ++++++++++++++------------ 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/scripts/gh-book/gdoc-xhtml-file.coffee b/scripts/gh-book/gdoc-xhtml-file.coffee index 2a0fbd64..dd3d7d5c 100644 --- a/scripts/gh-book/gdoc-xhtml-file.coffee +++ b/scripts/gh-book/gdoc-xhtml-file.coffee @@ -48,36 +48,6 @@ define [ ) return gdoc_transform_promise - injectHtml = (bodyhtml) -> - # bodyhtml is "..." - @set 'body', bodyhtml - - cleanupFailedImport = () -> - return - - importGoogleDoc = () -> - # alerts need to turned into log messages or deleted - gdocpicker_promise = newPicker() - gdocpicker_promise.done (data) -> - gdoc_html_promise = getGoogleDocHtml(data) - gdoc_html_promise.done (data, status, xhr) -> - html = data - alert "got html from google" - gdoc_transform_promise = transformGoogleDocHtml(html) - gdoc_transform_promise.done (data, status, xhr) -> - alert "gdoc2html service succeeded" - bodyhtml = data["html"] - injectHtml(bodyhtml) - gdoc_transform_promise.fail (data, status, xhr) -> - alert "gdoc service failed to tranform html into aloha ready html." - cleanupFailedImport() - gdoc_html_promise.fail (data, status, xhr) -> - alert "failed to get the google doc's html from google." - cleanupFailedImport() - gdocpicker_promise.fail -> - alert "canceled out of the google doc picker." - cleanupFailedImport() - # The `Content` model contains the following members: # # * `title` - an HTML title of the content @@ -94,12 +64,46 @@ define [ initialize: () -> super() - # super() does the following, so we do not - # @setNew() - # @id = "content/#{uuid()}" - # this don't go here, _loadComplex() aint right either but closer to the mark - importGoogleDoc() + _loadComplex: (promise) -> + gdocimport_promise = @_importGoogleDoc() + return gdocimport_promise + + _injectHtml: (bodyhtml) -> + # bodyhtml is "..." + @set 'body', bodyhtml + + _cleanupFailedImport: () -> + return + + _importGoogleDoc: () -> + _this = this + gdocimport_deferred = $.Deferred() + gdocimport_promise = gdocimport_deferred.promise() - @_loadComplex = (promise) -> - return promise + gdocpicker_promise = newPicker() + gdocpicker_promise.done (data) -> + gdoc_html_promise = getGoogleDocHtml(data) + gdoc_html_promise.done (data, status, xhr) -> + html = data + #alert "got html from google" + gdoc_transform_promise = transformGoogleDocHtml(html) + gdoc_transform_promise.done (data, status, xhr) -> + # alert "gdoc2html service succeeded" + bodyhtml = data["html"] + _this._injectHtml(bodyhtml) + gdocimport_promise.resolve() + gdoc_transform_promise.fail (data, status, xhr) -> + # alert "gdoc service failed to tranform html into aloha ready html." + _this._cleanupFailedImport() + gdocimport_promise.reject() + gdoc_html_promise.fail (data, status, xhr) -> + # alert "failed to get the google doc's html from google." + _this._cleanupFailedImport() + gdocimport_promise.reject() + gdocpicker_promise.fail -> + # alert "canceled out of the google doc picker." + _this._cleanupFailedImport() + gdocimport_promise.reject() + + return gdocimport_promise From dccbb25b147e0b474eee2529b19daf98d36d9553 Mon Sep 17 00:00:00 2001 From: bnwest Date: Mon, 30 Sep 2013 16:34:50 +0200 Subject: [PATCH 07/14] futz with this --- scripts/gh-book/gdoc-xhtml-file.coffee | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/scripts/gh-book/gdoc-xhtml-file.coffee b/scripts/gh-book/gdoc-xhtml-file.coffee index dd3d7d5c..b61db971 100644 --- a/scripts/gh-book/gdoc-xhtml-file.coffee +++ b/scripts/gh-book/gdoc-xhtml-file.coffee @@ -77,33 +77,32 @@ define [ return _importGoogleDoc: () -> - _this = this gdocimport_deferred = $.Deferred() gdocimport_promise = gdocimport_deferred.promise() gdocpicker_promise = newPicker() - gdocpicker_promise.done (data) -> + gdocpicker_promise.done (data) => gdoc_html_promise = getGoogleDocHtml(data) - gdoc_html_promise.done (data, status, xhr) -> + gdoc_html_promise.done (data, status, xhr) => html = data #alert "got html from google" gdoc_transform_promise = transformGoogleDocHtml(html) - gdoc_transform_promise.done (data, status, xhr) -> + gdoc_transform_promise.done (data, status, xhr) => # alert "gdoc2html service succeeded" bodyhtml = data["html"] - _this._injectHtml(bodyhtml) + @_injectHtml(bodyhtml) gdocimport_promise.resolve() - gdoc_transform_promise.fail (data, status, xhr) -> + gdoc_transform_promise.fail (data, status, xhr) => # alert "gdoc service failed to tranform html into aloha ready html." - _this._cleanupFailedImport() + @_cleanupFailedImport() gdocimport_promise.reject() - gdoc_html_promise.fail (data, status, xhr) -> + gdoc_html_promise.fail (data, status, xhr) => # alert "failed to get the google doc's html from google." - _this._cleanupFailedImport() + @_cleanupFailedImport() gdocimport_promise.reject() - gdocpicker_promise.fail -> + gdocpicker_promise.fail => # alert "canceled out of the google doc picker." - _this._cleanupFailedImport() + @_cleanupFailedImport() gdocimport_promise.reject() return gdocimport_promise From 377bc63a312744bc2e3f6ad9569e6600924eb4c1 Mon Sep 17 00:00:00 2001 From: bnwest Date: Mon, 30 Sep 2013 22:56:49 +0200 Subject: [PATCH 08/14] made some but not of phil's suggested changes --- scripts/gh-book/gdoc-xhtml-file.coffee | 43 +++++++++++++++++++------- 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/scripts/gh-book/gdoc-xhtml-file.coffee b/scripts/gh-book/gdoc-xhtml-file.coffee index b61db971..fc0ffff2 100644 --- a/scripts/gh-book/gdoc-xhtml-file.coffee +++ b/scripts/gh-book/gdoc-xhtml-file.coffee @@ -7,6 +7,13 @@ define [ 'gh-book/googlejsapi' ], (_, $, Backbone, ModuleModel, XhtmlModel) -> + GDOC_TO_HTML_URL = 'http://testing.oerpub.org/gdoc2html' # eventually `http://remix.oerpub.org/gdoc2html` + gdocsURL = (id) -> "https://docs.google.com/document/d/#{id}/export?format=html&confirm=no_antivirus" + + # the cannonical example of how to use google picker includes three functions + # newPicker(), createPicker(), and pickerCallback. and so do we except ours + # includes promises. + gdocpicker_deferred = undefined newPicker = () -> @@ -23,6 +30,7 @@ define [ return picker pickerCallback = (data) -> + # action can be { "cancel", "picked", "received", "loaded", "uploadProgress", "uploadScheduled", "uploadStateChange" } if data.action is google.picker.Action.PICKED gdocpicker_deferred.resolve(data) else if data.action is google.picker.Action.CANCEL @@ -30,8 +38,7 @@ define [ getGoogleDocHtml = (data) -> gdoc_resource_id = data.docs[0].id - html_url = 'https://docs.google.com/document/d/' + gdoc_resource_id + - '/export?format=html&confirm=no_antivirus' + html_url = gdocsURL(gdoc_resource_id) gdoc_html_promise = $.get(html_url) return gdoc_html_promise @@ -40,7 +47,7 @@ define [ dataType: "json" type: "POST" async: true - url: "http://testing.oerpub.org/gdoc2html" # evetually http://remix.oerpub.org/gdoc2html + url: GDOC_TO_HTML_URL data: html: html textbook_html: 0 @@ -56,22 +63,29 @@ define [ # * `keywords` - an array of keywords (eg `['constant', 'boltzmann constant']`) # * `authors` - an `Collection` of `User`s that are attributed as authors return class GoogleDocXhtmlModel extends XhtmlModel - mediaType: 'application/xhtml+xml' - - uniqueMediaType: 'application/vnd.org.cnx.gdoc-import' title: 'Google Document Import' - initialize: () -> - super() + # **NOTE:** The mediaType (`application/xhtml+xml`) is inherited from XhtmlModel + # because a successful import will 'appear' as a XHTML document. + # This mediaType is used in the OPF manifest + + # In order to add this type to the Add dropdown for a Book (OPF File) + # this model must have a unique mediaType (not `application/xhtml+xml`) + # This is used to register with `media-types` and is in the + # list of types `opf-file` accepts as a child (so it shows up in the filtered dropdown) + uniqueMediaType: 'application/vnd.org.cnx.gdoc-import' - _loadComplex: (promise) -> + _loadComplex: (fetchPromise) -> + # **NOTE:** `fetchPromise` is not used because this type can only be created as a new object + # (the fetchPromise is already resolved) gdocimport_promise = @_importGoogleDoc() return gdocimport_promise + # Saves the fetched and converted Document into this model for saving _injectHtml: (bodyhtml) -> - # bodyhtml is "..." - @set 'body', bodyhtml + # bodyhtml is "..." + @set 'body', bodyhtml _cleanupFailedImport: () -> return @@ -80,15 +94,20 @@ define [ gdocimport_deferred = $.Deferred() gdocimport_promise = gdocimport_deferred.promise() + # 1. Open the Google Doc picker dialog gdocpicker_promise = newPicker() gdocpicker_promise.done (data) => + # alert "selected a google doc" + # 2. Get the HTML for the Google Doc from Google gdoc_html_promise = getGoogleDocHtml(data) gdoc_html_promise.done (data, status, xhr) => html = data - #alert "got html from google" + # alert "got html from google" + # 3. Send the HTML to the transform service gdoc_transform_promise = transformGoogleDocHtml(html) gdoc_transform_promise.done (data, status, xhr) => # alert "gdoc2html service succeeded" + # 4. Inject the cleaned HTML into the Model bodyhtml = data["html"] @_injectHtml(bodyhtml) gdocimport_promise.resolve() From 33ccd6b0398a69432559c10c65d4c4038cf34bf1 Mon Sep 17 00:00:00 2001 From: bnwest Date: Tue, 1 Oct 2013 15:18:47 +0200 Subject: [PATCH 09/14] reworked the promise nest using jquery 1.8 then()s. --- scripts/gh-book/gdoc-xhtml-file.coffee | 51 +++++++++----------------- 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/scripts/gh-book/gdoc-xhtml-file.coffee b/scripts/gh-book/gdoc-xhtml-file.coffee index fc0ffff2..075a245e 100644 --- a/scripts/gh-book/gdoc-xhtml-file.coffee +++ b/scripts/gh-book/gdoc-xhtml-file.coffee @@ -91,37 +91,20 @@ define [ return _importGoogleDoc: () -> - gdocimport_deferred = $.Deferred() - gdocimport_promise = gdocimport_deferred.promise() - - # 1. Open the Google Doc picker dialog - gdocpicker_promise = newPicker() - gdocpicker_promise.done (data) => - # alert "selected a google doc" - # 2. Get the HTML for the Google Doc from Google - gdoc_html_promise = getGoogleDocHtml(data) - gdoc_html_promise.done (data, status, xhr) => - html = data - # alert "got html from google" - # 3. Send the HTML to the transform service - gdoc_transform_promise = transformGoogleDocHtml(html) - gdoc_transform_promise.done (data, status, xhr) => - # alert "gdoc2html service succeeded" - # 4. Inject the cleaned HTML into the Model - bodyhtml = data["html"] - @_injectHtml(bodyhtml) - gdocimport_promise.resolve() - gdoc_transform_promise.fail (data, status, xhr) => - # alert "gdoc service failed to tranform html into aloha ready html." - @_cleanupFailedImport() - gdocimport_promise.reject() - gdoc_html_promise.fail (data, status, xhr) => - # alert "failed to get the google doc's html from google." - @_cleanupFailedImport() - gdocimport_promise.reject() - gdocpicker_promise.fail => - # alert "canceled out of the google doc picker." - @_cleanupFailedImport() - gdocimport_promise.reject() - - return gdocimport_promise + promise = newPicker() # 1. Open the picker dialog + .then((data) => + alert "google doc selected" + getGoogleDocHtml data # 2. Get the HTML from Google + , => + console.warning "GOOGLE DOC IMPORT: picker dialog was cancelled" + ).then((html) => + alert "got html for google doc" + transformGoogleDocHtml html # 3. Send the HTML to the transform service + , => + console.warning "GOOGLE DOC IMPORT: failed to get google doc htmlform google" + ).then ((json) => + alert "transformed google doc html via remix service" + _this._injectHtml json.html # 4. Inject the cleaned HTML into the Model + ), => + console.warning "GOOGLE DOC IMPORT: failed to transform google doc html via remix service" + promise From a6cacf34fd0cf369a7f06ceb3f926474fcafc096 Mon Sep 17 00:00:00 2001 From: bnwest Date: Tue, 1 Oct 2013 16:14:00 +0200 Subject: [PATCH 10/14] moving console messages out of the promise nest, which now looks much cleaner. commented out alerts. --- scripts/gh-book/gdoc-xhtml-file.coffee | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/scripts/gh-book/gdoc-xhtml-file.coffee b/scripts/gh-book/gdoc-xhtml-file.coffee index 075a245e..092aded3 100644 --- a/scripts/gh-book/gdoc-xhtml-file.coffee +++ b/scripts/gh-book/gdoc-xhtml-file.coffee @@ -35,11 +35,14 @@ define [ gdocpicker_deferred.resolve(data) else if data.action is google.picker.Action.CANCEL gdocpicker_deferred.reject() + console.warning "GOOGLE DOC IMPORT: picker dialog was cancelled" getGoogleDocHtml = (data) -> gdoc_resource_id = data.docs[0].id html_url = gdocsURL(gdoc_resource_id) gdoc_html_promise = $.get(html_url) + gdoc_html_promise.fail -> + console.warning "GOOGLE DOC IMPORT: failed to get google doc htmlform google" return gdoc_html_promise transformGoogleDocHtml = (html) -> @@ -53,6 +56,8 @@ define [ textbook_html: 0 copy_images: 0 ) + gdoc_transform_promise. fail -> + console.warning "GOOGLE DOC IMPORT: failed to transform google doc html via remix service" return gdoc_transform_promise # The `Content` model contains the following members: @@ -93,18 +98,15 @@ define [ _importGoogleDoc: () -> promise = newPicker() # 1. Open the picker dialog .then((data) => - alert "google doc selected" + # alert "google doc selected" getGoogleDocHtml data # 2. Get the HTML from Google - , => - console.warning "GOOGLE DOC IMPORT: picker dialog was cancelled" ).then((html) => - alert "got html for google doc" + # alert "got html for google doc" transformGoogleDocHtml html # 3. Send the HTML to the transform service - , => - console.warning "GOOGLE DOC IMPORT: failed to get google doc htmlform google" - ).then ((json) => - alert "transformed google doc html via remix service" + ).then((json) => + # alert "transformed google doc html via remix service" _this._injectHtml json.html # 4. Inject the cleaned HTML into the Model - ), => - console.warning "GOOGLE DOC IMPORT: failed to transform google doc html via remix service" + ).fail( + console.warning "GOOGLE DOC IMPORT: was not successful" + ) promise From db5a263896c3b233a8f8fa6b062e3e5554a8ba41 Mon Sep 17 00:00:00 2001 From: bnwest Date: Tue, 1 Oct 2013 17:45:01 +0200 Subject: [PATCH 11/14] fixed final fail() in promise nest --- scripts/gh-book/gdoc-xhtml-file.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/gh-book/gdoc-xhtml-file.coffee b/scripts/gh-book/gdoc-xhtml-file.coffee index 092aded3..f82c3d7b 100644 --- a/scripts/gh-book/gdoc-xhtml-file.coffee +++ b/scripts/gh-book/gdoc-xhtml-file.coffee @@ -106,7 +106,7 @@ define [ ).then((json) => # alert "transformed google doc html via remix service" _this._injectHtml json.html # 4. Inject the cleaned HTML into the Model - ).fail( + ).fail(() => console.warning "GOOGLE DOC IMPORT: was not successful" ) promise From ff0f628d57cfeb0fa3d509b63cb5a030e978145e Mon Sep 17 00:00:00 2001 From: bnwest Date: Tue, 1 Oct 2013 17:57:01 +0200 Subject: [PATCH 12/14] console.warn() not warning() --- scripts/gh-book/gdoc-xhtml-file.coffee | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/gh-book/gdoc-xhtml-file.coffee b/scripts/gh-book/gdoc-xhtml-file.coffee index f82c3d7b..0dd246f2 100644 --- a/scripts/gh-book/gdoc-xhtml-file.coffee +++ b/scripts/gh-book/gdoc-xhtml-file.coffee @@ -35,14 +35,14 @@ define [ gdocpicker_deferred.resolve(data) else if data.action is google.picker.Action.CANCEL gdocpicker_deferred.reject() - console.warning "GOOGLE DOC IMPORT: picker dialog was cancelled" + console.warn "GOOGLE DOC IMPORT: picker dialog was cancelled" getGoogleDocHtml = (data) -> gdoc_resource_id = data.docs[0].id html_url = gdocsURL(gdoc_resource_id) gdoc_html_promise = $.get(html_url) gdoc_html_promise.fail -> - console.warning "GOOGLE DOC IMPORT: failed to get google doc htmlform google" + console.warn "GOOGLE DOC IMPORT: failed to get google doc htmlform google" return gdoc_html_promise transformGoogleDocHtml = (html) -> @@ -57,7 +57,7 @@ define [ copy_images: 0 ) gdoc_transform_promise. fail -> - console.warning "GOOGLE DOC IMPORT: failed to transform google doc html via remix service" + console.warn "GOOGLE DOC IMPORT: failed to transform google doc html via remix service" return gdoc_transform_promise # The `Content` model contains the following members: @@ -107,6 +107,6 @@ define [ # alert "transformed google doc html via remix service" _this._injectHtml json.html # 4. Inject the cleaned HTML into the Model ).fail(() => - console.warning "GOOGLE DOC IMPORT: was not successful" + console.warn "GOOGLE DOC IMPORT: was not successful" ) promise From 9ac44cc8712d35c0bfef2e49191a9b95b4ce2b9e Mon Sep 17 00:00:00 2001 From: bnwest Date: Tue, 1 Oct 2013 18:55:15 +0200 Subject: [PATCH 13/14] camelCase it is. --- scripts/gh-book/gdoc-xhtml-file.coffee | 30 +++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/scripts/gh-book/gdoc-xhtml-file.coffee b/scripts/gh-book/gdoc-xhtml-file.coffee index 0dd246f2..80d729c9 100644 --- a/scripts/gh-book/gdoc-xhtml-file.coffee +++ b/scripts/gh-book/gdoc-xhtml-file.coffee @@ -14,12 +14,12 @@ define [ # newPicker(), createPicker(), and pickerCallback. and so do we except ours # includes promises. - gdocpicker_deferred = undefined + gdocPickerDeferred = undefined newPicker = () -> google.load('picker', '1', {"callback" : createPicker}) - gdocpicker_deferred = $.Deferred() - return gdocpicker_deferred.promise() + gdocPickerDeferred = $.Deferred() + return gdocPickerDeferred.promise() createPicker = () -> picker = new google.picker.PickerBuilder(). @@ -32,21 +32,21 @@ define [ pickerCallback = (data) -> # action can be { "cancel", "picked", "received", "loaded", "uploadProgress", "uploadScheduled", "uploadStateChange" } if data.action is google.picker.Action.PICKED - gdocpicker_deferred.resolve(data) + gdocPickerDeferred.resolve(data) else if data.action is google.picker.Action.CANCEL - gdocpicker_deferred.reject() + gdocPickerDeferred.reject() console.warn "GOOGLE DOC IMPORT: picker dialog was cancelled" getGoogleDocHtml = (data) -> - gdoc_resource_id = data.docs[0].id - html_url = gdocsURL(gdoc_resource_id) - gdoc_html_promise = $.get(html_url) - gdoc_html_promise.fail -> + gdocResourceId = data.docs[0].id + htmlUrl = gdocsURL(gdocResourceId) + gdocHtmlPromise = $.get(htmlUrl) + gdocHtmlPromise.fail -> console.warn "GOOGLE DOC IMPORT: failed to get google doc htmlform google" - return gdoc_html_promise + return gdocHtmlPromise transformGoogleDocHtml = (html) -> - gdoc_transform_promise = $.ajax( + gdocTransformPromise = $.ajax( dataType: "json" type: "POST" async: true @@ -56,9 +56,9 @@ define [ textbook_html: 0 copy_images: 0 ) - gdoc_transform_promise. fail -> + gdocTransformPromise.fail -> console.warn "GOOGLE DOC IMPORT: failed to transform google doc html via remix service" - return gdoc_transform_promise + return gdocTransformPromise # The `Content` model contains the following members: # @@ -84,8 +84,8 @@ define [ _loadComplex: (fetchPromise) -> # **NOTE:** `fetchPromise` is not used because this type can only be created as a new object # (the fetchPromise is already resolved) - gdocimport_promise = @_importGoogleDoc() - return gdocimport_promise + gdocImportPromise = @_importGoogleDoc() + return gdocImportPromise # Saves the fetched and converted Document into this model for saving _injectHtml: (bodyhtml) -> From 4790ad5e0ac79e9383e554b0315c8b4f284b2993 Mon Sep 17 00:00:00 2001 From: bnwest Date: Wed, 2 Oct 2013 05:11:40 +0200 Subject: [PATCH 14/14] added cleanup call on failure --- scripts/gh-book/gdoc-xhtml-file.coffee | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/gh-book/gdoc-xhtml-file.coffee b/scripts/gh-book/gdoc-xhtml-file.coffee index 80d729c9..01ad25cd 100644 --- a/scripts/gh-book/gdoc-xhtml-file.coffee +++ b/scripts/gh-book/gdoc-xhtml-file.coffee @@ -11,7 +11,7 @@ define [ gdocsURL = (id) -> "https://docs.google.com/document/d/#{id}/export?format=html&confirm=no_antivirus" # the cannonical example of how to use google picker includes three functions - # newPicker(), createPicker(), and pickerCallback. and so do we except ours + # newPicker(), createPicker(), and pickerCallback(). and so do we except ours # includes promises. gdocPickerDeferred = undefined @@ -105,8 +105,9 @@ define [ transformGoogleDocHtml html # 3. Send the HTML to the transform service ).then((json) => # alert "transformed google doc html via remix service" - _this._injectHtml json.html # 4. Inject the cleaned HTML into the Model + @_injectHtml json.html # 4. Inject the cleaned HTML into the Model ).fail(() => console.warn "GOOGLE DOC IMPORT: was not successful" + @_cleanupFailedImport() ) promise