From ad07befd3582faba3d36c71918630441df571287 Mon Sep 17 00:00:00 2001 From: bnwest Date: Wed, 25 Sep 2013 02:57:18 +0200 Subject: [PATCH 01/13] 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 7f66b09c8db237f5cc5609796190e9dc5060f70b Mon Sep 17 00:00:00 2001 From: bnwest Date: Wed, 25 Sep 2013 21:44:56 +0200 Subject: [PATCH 02/13] 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 | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/gh-book/app.coffee b/scripts/gh-book/app.coffee index 146915ac..fd50157c 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' @@ -17,7 +18,7 @@ define [ 'cs!gh-book/loading' 'cs!configs/github.coffee' '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() @@ -94,6 +95,7 @@ define [ mediaTypes.add TocNode mediaTypes.add BinaryFile, {mediaType:'image/png'} mediaTypes.add BinaryFile, {mediaType:'image/jpeg'} + mediaTypes.add GoogleDocXhtmlFile, {mediaType:GoogleDocXhtmlFile::uniqueMediaType} # set which media formats are allowed # at the toplevel of the content 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 761ab6b1..993f1bdc 100644 --- a/scripts/gh-book/opf-file.coffee +++ b/scripts/gh-book/opf-file.coffee @@ -4,6 +4,7 @@ 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' @@ -16,6 +17,7 @@ define [ allContent, loadable, XhtmlFile, + GoogleDocXhtmlFile, TocNode, TocPointerNode, Utils, @@ -30,7 +32,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 746a83fa414ae0942fa975d184aefd7174766522 Mon Sep 17 00:00:00 2001 From: bnwest Date: Fri, 27 Sep 2013 14:07:02 +0200 Subject: [PATCH 03/13] stype google doc import drop down item --- scripts/gh-book/gh-book.less | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/gh-book/gh-book.less b/scripts/gh-book/gh-book.less index f36a1fef..3c81d08d 100755 --- a/scripts/gh-book/gh-book.less +++ b/scripts/gh-book/gh-book.less @@ -9,6 +9,7 @@ .x-media-type-icon('application/xhtml+xml'; "content/module"; #999; "\f0f6"); /* icon-file-alt */ .x-media-type-icon('application/oebps-package+xml'; "Book"; @toc-color; "\f02d"); /* icon-book */ .x-media-type-icon('application/vnd.org.cnx.section'; "book division"; #999; ""); /* icon-folder-open */ +.x-media-type-icon('application/vnd.org.cnx.gdoc-import'; "Google Doc Import"; #999; "\f0d5"); /* icon-google-plus */ #login-advanced-wrapper { margin-top: 1em; From e36682a0cb0392c1b1ee33dc594135176e1ac0c6 Mon Sep 17 00:00:00 2001 From: bnwest Date: Fri, 27 Sep 2013 19:00:12 +0200 Subject: [PATCH 04/13] 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/13] 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 b465bfdcb97a72b1cf1eb367703313a9345e5c01 Mon Sep 17 00:00:00 2001 From: bnwest Date: Mon, 30 Sep 2013 16:13:03 +0200 Subject: [PATCH 06/13] 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 35f80dd7645c3c4e457b20fa235f3db647605bb2 Mon Sep 17 00:00:00 2001 From: bnwest Date: Mon, 30 Sep 2013 16:34:50 +0200 Subject: [PATCH 07/13] 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 d4dce814720df41ed95251a13b76d19e9c21c3e5 Mon Sep 17 00:00:00 2001 From: bnwest Date: Mon, 30 Sep 2013 22:56:49 +0200 Subject: [PATCH 08/13] 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 cd905e20fd0a1d5d1aee8c6586e89cd5055cbbef Mon Sep 17 00:00:00 2001 From: bnwest Date: Tue, 1 Oct 2013 15:18:47 +0200 Subject: [PATCH 09/13] 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 d1ab8d690ad5c87ed51dc2a29ba7311464dcfba9 Mon Sep 17 00:00:00 2001 From: bnwest Date: Tue, 1 Oct 2013 16:14:00 +0200 Subject: [PATCH 10/13] 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 4c1a43411f5ba42a2db0829e5a8ec8ae9e8bf3ff Mon Sep 17 00:00:00 2001 From: Philip Schatz Date: Tue, 1 Oct 2013 20:02:01 -0400 Subject: [PATCH 11/13] clean up code --- scripts/gh-book/gdoc-xhtml-file.coffee | 131 +++++++++++-------------- 1 file changed, 56 insertions(+), 75 deletions(-) diff --git a/scripts/gh-book/gdoc-xhtml-file.coffee b/scripts/gh-book/gdoc-xhtml-file.coffee index 092aded3..b7f99641 100644 --- a/scripts/gh-book/gdoc-xhtml-file.coffee +++ b/scripts/gh-book/gdoc-xhtml-file.coffee @@ -7,106 +7,87 @@ define [ 'gh-book/googlejsapi' ], (_, $, Backbone, ModuleModel, XhtmlModel) -> + # Picker Reference: https://developers.google.com/picker/docs/reference + 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 - + # Opens a new Modal Dialog allowing the user to pick a Google Doc to import 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) -> - # 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 - gdocpicker_deferred.reject() - console.warning "GOOGLE DOC IMPORT: picker dialog was cancelled" - + promise = $.Deferred() + + google.load 'picker', '1', + callback: () => + # Create a new Doc Picker Modal popup and re-ify the promise when + # 1. a document is selected + # 2. the dialog is canceled/closed + picker = new google.picker.PickerBuilder() + picker.addView(google.picker.ViewId.DOCUMENTS) + picker.setCallback (data) -> + switch data.action + when google.picker.Action.PICKED then promise.resolve(data) + when google.picker.Action.CANCEL then promise.reject('USER_CANCELLED') + else + promise.progress(data) + picker.build() + picker.setVisible(true) + return picker + + return promise.promise() + + # Retreive the HTML of the 1st Google Doc selected in the Picker 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 + resourceId = data.docs[0].id + htmlUrl = gdocsURL(resourceId) + promise = $.get(htmlUrl) + return promise + # Clean up HTML retrieved from Google to be used in the Editor. + # Makes an AJAX call to a service that converts the HTML transformGoogleDocHtml = (html) -> - gdoc_transform_promise = $.ajax( - dataType: "json" - type: "POST" - async: true - url: GDOC_TO_HTML_URL + promise = $.ajax + url: GDOC_TO_HTML_URL + type: 'POST' + dataType: 'json' + async: true data: html: html 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: - # - # * `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 promise + return class GoogleDocXhtmlModel extends XhtmlModel title: 'Google Document Import' - # **NOTE:** The mediaType (`application/xhtml+xml`) is inherited from XhtmlModel - # because a successful import will 'appear' as a XHTML document. + # **NOTE:** The mediaType 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 + # 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' + # Saves the fetched and converted Document into this model for saving + _injectHtml: (html) -> @set('body', html) # html is '...' + + # Pop up the Picker dialog when this Model is added to a book _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 + promise = newPicker() # 1. Open the picker dialog + .then (data) => + return getGoogleDocHtml(data) # 2. Get the HTML from Google + .then (html) => + return transformGoogleDocHtml(html) # 3. Send the HTML to the transform service + .then (json) => + @_injectHtml(json.html) # 4. Inject the cleaned HTML into the Model - _cleanupFailedImport: () -> - return + promise.fail => + console.warn('BUG: Import failed (maybe the user canceled it) and there is no cleanup code') - _importGoogleDoc: () -> - promise = newPicker() # 1. Open the picker dialog - .then((data) => - # alert "google doc selected" - getGoogleDocHtml data # 2. Get the HTML from Google - ).then((html) => - # alert "got html for google doc" - 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 - ).fail( - console.warning "GOOGLE DOC IMPORT: was not successful" - ) - promise + return promise From 2a613efc6d7aeb8eac6ea239ef5934aa0f82cce0 Mon Sep 17 00:00:00 2001 From: Izak Burger Date: Wed, 16 Oct 2013 15:50:25 +0200 Subject: [PATCH 12/13] Fix breakage when context model is null. --- scripts/controllers/routing.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/controllers/routing.coffee b/scripts/controllers/routing.coffee index f71da6a7..6b7e9a22 100644 --- a/scripts/controllers/routing.coffee +++ b/scripts/controllers/routing.coffee @@ -102,7 +102,7 @@ define [ # these are needed on the next render as a pointers to things # Always use the dereferenced node because content can be in more than one book @_currentModel = model.dereferencePointer?() or model - @_currentContext = contextModel.dereferencePointer?() or contextModel + @_currentContext = contextModel and contextModel.dereferencePointer?() or contextModel # this is needed right now to render the workspace @_currentContext?.set('_selected', true) From 9905470636b5087b8160b80ef99eb45b050ee603 Mon Sep 17 00:00:00 2001 From: Izak Burger Date: Wed, 16 Oct 2013 15:50:45 +0200 Subject: [PATCH 13/13] Distinguish between pickerbuilder and picker correctly. --- 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 b7f99641..dd8f4831 100644 --- a/scripts/gh-book/gdoc-xhtml-file.coffee +++ b/scripts/gh-book/gdoc-xhtml-file.coffee @@ -21,15 +21,15 @@ define [ # Create a new Doc Picker Modal popup and re-ify the promise when # 1. a document is selected # 2. the dialog is canceled/closed - picker = new google.picker.PickerBuilder() - picker.addView(google.picker.ViewId.DOCUMENTS) - picker.setCallback (data) -> + builder = new google.picker.PickerBuilder() + builder.addView(google.picker.ViewId.DOCUMENTS) + builder.setCallback (data) -> switch data.action when google.picker.Action.PICKED then promise.resolve(data) when google.picker.Action.CANCEL then promise.reject('USER_CANCELLED') else promise.progress(data) - picker.build() + picker = builder.build() picker.setVisible(true) return picker