diff --git a/main/src/com/google/refine/commands/project/SetProjectMetaDataCommand.java b/main/src/com/google/refine/commands/project/SetProjectMetaDataCommand.java new file mode 100644 index 000000000..8cd2b175c --- /dev/null +++ b/main/src/com/google/refine/commands/project/SetProjectMetaDataCommand.java @@ -0,0 +1,52 @@ +package com.google.refine.commands.project; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONException; +import org.json.JSONTokener; +import org.json.JSONWriter; + +import com.google.refine.ProjectManager; +import com.google.refine.ProjectMetadata; +import com.google.refine.commands.Command; +import com.google.refine.model.Project; + +public class SetProjectMetaDataCommand extends Command { + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + Project project = request.getParameter("project") != null ? getProject(request) : null; + String metaName = request.getParameter("name"); + String valueString = request.getParameter("value"); + ProjectMetadata meta = null; + + if (project == null) { + respond(response, "{ \"code\" : \"error\", \"message\" : \"Project cannot be found\" }"); + return; + } + + meta = project.getMetadata(); + try { + response.setCharacterEncoding("UTF-8"); + response.setHeader("Content-Type", "application/json"); + JSONWriter writer = new JSONWriter(response.getWriter()); + + Object o = valueString == null ? null : new JSONTokener(valueString).nextValue(); + + meta.setAnyField(metaName, valueString); + ProjectManager.singleton.saveMetadata(meta, project.id); + + respond(response, "{ \"code\" : \"ok\" }"); + } catch (JSONException e) { + respondException(response, e); + } catch (Exception e) { + respondException(response, e); + } + } + +} diff --git a/main/webapp/modules/core/scripts/index/edit-metadata-dialog.js b/main/webapp/modules/core/scripts/index/edit-metadata-dialog.js new file mode 100644 index 000000000..c3b86b5c5 --- /dev/null +++ b/main/webapp/modules/core/scripts/index/edit-metadata-dialog.js @@ -0,0 +1,81 @@ + + +function EditMetadataDialog(metaData) { + this._metaDataUIs = []; + this._metaData = metaData; + + this._MetaDataUI = function(tr, key, value, project) { + var self = this; + + var td0 = tr.insertCell(0); + $(td0).text(key); + + var td1 = tr.insertCell(1); + $(td1).text((value !== null) ? value : ""); + + var td2 = tr.insertCell(2); + + $('