Skip to content

Commit

Permalink
Merge pull request #15 from aptoma/develop
Browse files Browse the repository at this point in the history
[Digital Assets] Added functions for digital asset functionality
  • Loading branch information
Michael committed Sep 28, 2015
2 parents 94223fe + 13eb778 commit 2b70d4f
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 4 deletions.
13 changes: 13 additions & 0 deletions UPDATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Upgrading from v1.* to v2.0
==========================
When upgrading from v1.* to v2.0 there are two important points to keep in mind:
* The parent object has been renamed to ```PluginAPI```, so all occurences of ```AppAPI``` should be changed.
* There is no longer an authentication step, so the ```AppAPI.doStandardAuthentication``` and ```AppAPI.doDirectAuthentication``` functions have been removed.
* The removal of the authentication step also means that the ```appAuthenticated``` event is deprecated. DrPublish is still sending the event for backwards compatability, but it will be removed in a future version of DrPublish.


Why remove the authentication?
==============================
We decided to remove the authentication step since it was making development of plugins a lot harder for very little benefit. We added the authentication step to ensure that it was only possible to open up plugins in the plugin pane, since we thought that opening an unknown web page could give the journalists the impression that it the web page was a part of DrPublish even though that was not the case. But with the requirement to register plugins through the publication administration there is very little chance of a web page being loaded there without someone actually wanting it there, a DNS hijacking is the most probable cause of that happening. And even if it were to happen the new, stricter ways that browsers handle communication between the parent frame and the iframe there should not be any way for the rogue iframe to send information to DrPublish.

So with this in mind we decided to remove the authentication step. This will make plugin development easier, since the plugin api is now a pure Javascript library, and the plugins should load faster since they will not have to wait for the authentication process to finish.
115 changes: 113 additions & 2 deletions js/AH5Communicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
PluginAPI.Editor = (function () {
"use strict";




/**
* This will be used by editor apps to communicate with the editor
*
Expand All @@ -15,11 +18,34 @@ PluginAPI.Editor = (function () {
* @exports PluginAPI/Editor
*/
var AH5Communicator = function() {

var selectedPluginElement = null;


var pluginElementSelected = function(element) {
PluginAPI.selectedPluginElement = element
}

var pluginElementDeselected = function() {
PluginAPI.selectedPluginElement = null;
}

this.DEBUG = false;

PluginAPI.addListeners({
pluginElementClicked: pluginElementSelected,
pluginElementDeselected: pluginElementDeselected
});

};


AH5Communicator.prototype.selectedPluginElement = null;


/**
* Get name of current active editor
*
*
* @param {function} callback function(String)
*/
AH5Communicator.prototype.getActiveEditor = function (callback) {
Expand All @@ -41,7 +67,7 @@ PluginAPI.Editor = (function () {
* // callback function
* // first parameter is id of the app element
* // second paramter is id of closest element to the trigger element that has an id
* // in code: $(event.triggerElement).closest('[id]').attr('id');
* // in code: $(event.triggerElement).closest('[id]').attr('id');
* }
* })
*/
Expand Down Expand Up @@ -327,6 +353,91 @@ PluginAPI.Editor = (function () {
AH5Communicator.prototype.updateAssetMedia = function(data, callback) {
PluginAPI.request('update-asset-media', data, callback);
};

AH5Communicator.prototype.insertEmbeddedMedia = function(markup, data, callback) {
var insert = function(dpArticleId, callback) {
data.internalId = dpArticleId;
var element = $('<div/>');
element.attr('id', 'asset-' + dpArticleId);
element.attr('data-internal-id', dpArticleId);
element.attr('data-external-id', data.externalId);
element.addClass(data.assetClass);
var customMarkup = $(markup);
element.append(customMarkup);
this.insertElement(element, { select: true} , callback)
}.bind(this);

var cb = function(callback) {
PluginAPI.request('update-embedded-asset', data, callback);
};

if (PluginAPI.selectedPluginElement) {
var dpArticleId = PluginAPI.selectedPluginElement.dpArticleId;
if (!dpArticleId) {
throw "Selected plugin element: expected dpArticleId not found (tried reading from attribute 'data-internal-id')";
}
insert(dpArticleId, cb);
} else {
PluginAPI.createEmbeddedObject(
data.embeddedTypeId,
function(dpArticleId) {
insert(dpArticleId, cb);
}
);
}
};

AH5Communicator.prototype.insertEmbeddedMedia = function(markup, data, callback) {

var replaceElement = false;
if (PluginAPI.selectedPluginElement) {
if (data.assetSource !== PluginAPI.getAppName()) {
PluginAPI.showErrorMsg("Can't update selected plugin element since it doesn't belong to the '" + PluginAPI.getAppName() + "' plugin");
return;
} else {
replaceElement = true;
}
}

var insert = function(dpArticleId, callback) {
data.internalId = dpArticleId;
var elementId = 'asset-' + dpArticleId;
var element = $('<div/>');
element.attr('id', elementId);
element.attr('data-internal-id', dpArticleId);
element.attr('data-external-id', data.externalId);
element.addClass(data.assetClass);
var customMarkup = $(markup);
element.append(customMarkup);
if (!replaceElement) {
this.insertElement(element, {select: true});
} else {
this.replaceElementById(elementId, element.get(0).outerHTML, {select: true});
}
if (typeof callback === 'function') {
callback();
}
}.bind(this);

var updateEmbeddedAssetRequest = function(callback) {
PluginAPI.request('update-embedded-asset', data, callback);
};

if (PluginAPI.selectedPluginElement) {
var dpArticleId = PluginAPI.selectedPluginElement.dpArticleId;
if (!dpArticleId) {
throw "Selected plugin element: expected dpArticleId not found (tried reading from attribute 'data-internal-id')";
}
insert(dpArticleId, function() {updateEmbeddedAssetRequest(callback)});
} else {
PluginAPI.createEmbeddedObject(
data.embeddedTypeId,
function(dpArticleId) {
insert(dpArticleId, function() {updateEmbeddedAssetRequest(callback)});
}
);
}
};

return new AH5Communicator();

Expand Down
20 changes: 20 additions & 0 deletions js/ArticleCommunicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,26 @@ PluginAPI.Article = (function() {
PluginAPI.request('article-id-get', null, callback);
};


/**
* Get the guid of the article package currently edited
*
* @param {Function} callback function(Int), id of the current article
*/
ArticleCommunicator.prototype.getPackageId = function(callback) {
PluginAPI.request('package-id-get', null, callback);
};


/**
* Get the guid of the article package currently edited
*
* @param {Function} callback function(Int), id of the current article
*/
ArticleCommunicator.prototype.getPackageGuid = function(callback) {
PluginAPI.request('package-guid-get', null, callback);
};

/**
* Clear the meta information summary
*
Expand Down
5 changes: 3 additions & 2 deletions js/PluginAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var PluginAPI = (function() {
this.errorListeners = new Listeners();
this.eventListeners = new Listeners();
this.appName = '';
this.selectedPluginElement = null;

var self = this;

Expand Down Expand Up @@ -71,7 +72,7 @@ var PluginAPI = (function() {
console.info(this.getAppName() + ': Requesting ' + callSpec + ' from parent with data', data);
}

if (data === null) {
if (!data) {
data = {};
}

Expand Down Expand Up @@ -432,7 +433,7 @@ var PluginAPI = (function() {
var self = this;
self.eventListeners.add(name, callback);
this.request('on-api-event', {
name: name,
name: name
});
};

Expand Down

0 comments on commit 2b70d4f

Please sign in to comment.