May 032014
 

In the previous post , we explained how to writer the export part of the server side part of the import-export plugin. But with almost everything done, we missed one thing, the implementation of the export option from one of the menus in DM webclient.

The place to click the export action will be inside the topicmap drop-down menu.

First we need to create the directory structure for our client side, that is, inside /src/main you have to create

resources/web/script 

and in there the file plugin.js

Once the plugin.js file is created, we have to add our plugin, for that you have to invoke dm client (dm4c)

dm4c.add_plugin("net.abriraqui.import-export", function(){
...
 }

Then dmc4 provides a listener that will allow you add elements to the topicmap menu. The elements that we will add are: a separator and the new item with “Export Topicmap” label, that will execute a export_topicmap method.

dm4c.add_listener("post_refresh_topicmap_menu", function(topicmap_menu) {
  topicmap_menu.add_separator()
  topicmap_menu.add_item({
    label: "Export Topicmap",
    handler: export_topicmap
})
}

and of course, we need to write the export_topicmap method, which will be quite simple. We define the uri for the export action, “/import-export/export”. Since we want to show an alert box that tells us that the topicmap has been exported, we first get the topicmap and then in the alert we call the get_id() method to know which topic map are we in.

function export_topicmap(){
 dm4c.restc.request("POST", "/import-export/export") 
 var topicmap =   dm4c.get_plugin("de.deepamehta.topicmaps").get_topicmap()
 alert("Export of topicmap " + topicmap.get_id() + " complete")
 }

Once done that, now we can finally check into our runner directory, in the root directory of your plugin, for the topicmap-XXX.json file with the info of the topicmap exported.

Implementing export topicmap option

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)