Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Exhibit-inputex-extension 0.1-alpha

  • Loading branch information...
commit 49490be7c423f4ce0a720beff9936ec223672284 1 parent 96dcebb
@neyric authored
View
2  README
@@ -0,0 +1,2 @@
+
+An extension for exhibit to make data editable using inputEx forms
View
70 inputex-extension.js
@@ -0,0 +1,70 @@
+/*==================================================
+ * Simile Exhibit inputEx Extension
+ * http://javascript.neyric.com/inputex
+ *==================================================
+ */
+
+Exhibit.inputExExtension = {
+ params: {
+ bundle: false
+ }
+};
+
+(function() {
+ var javascriptFiles = [
+ "editor.js"
+ ];
+ var cssFiles = [
+ "editor.css"
+ ];
+
+ var url = SimileAjax.findScript(document, "/inputex-extension.js");
+ if (url == null) {
+ SimileAjax.Debug.exception(new Error("Failed to derive URL prefix for Simile Exhibit Map Extension code files"));
+ return;
+ }
+ Exhibit.inputExExtension.urlPrefix = url.substr(0, url.indexOf("inputex-extension.js"));
+ var paramTypes = { bundle: Boolean };
+ SimileAjax.parseURLParameters(url, Exhibit.inputExExtension.params, paramTypes);
+
+
+ var scriptURLs = [];
+ var cssURLs = [];
+
+ scriptURLs.push("/inputex/trunk/lib/yui/yahoo-dom-event/yahoo-dom-event.js");
+ scriptURLs.push("/inputex/trunk/lib/yui/container/container-min.js");
+ scriptURLs.push("/inputex/trunk/lib/yui/element/element-beta-min.js");
+ scriptURLs.push("/inputex/trunk/lib/yui/button/button-min.js");
+ scriptURLs.push("/inputex/trunk/lib/yui/animation/animation-min.js");
+ scriptURLs.push("/inputex/trunk/lib/yui/calendar/calendar-min.js");
+ scriptURLs.push("/inputex/trunk/js/inputex.js");
+ scriptURLs.push("/inputex/trunk/js/Field.js");
+ scriptURLs.push("/inputex/trunk/js/Group.js");
+ scriptURLs.push("/inputex/trunk/js/Visus.js");
+ scriptURLs.push("/inputex/trunk/js/fields/StringField.js");
+ scriptURLs.push("/inputex/trunk/js/fields/SelectField.js");
+ scriptURLs.push("/inputex/trunk/js/fields/EmailField.js");
+ scriptURLs.push("/inputex/trunk/js/fields/UrlField.js");
+ scriptURLs.push("/inputex/trunk/js/fields/ListField.js");
+ scriptURLs.push("/inputex/trunk/js/fields/InPlaceEdit.js");
+ scriptURLs.push("/inputex/trunk/js/fields/UrlField.js");
+ scriptURLs.push("/inputex/trunk/js/fields/DateField.js");
+ scriptURLs.push("/inputex/trunk/js/fields/DatePickerField.js");
+
+ cssURLs.push("/inputex/trunk/lib/yui/reset/reset-min.css");
+ cssURLs.push("/inputex/trunk/lib/yui/fonts/fonts-min.css");
+ cssURLs.push("/inputex/trunk/lib/yui/grids/grids-min.css");
+ cssURLs.push("/inputex/trunk/lib/yui/container/assets/container.css");
+ cssURLs.push("/inputex/trunk/lib/yui/assets/skins/sam/skin.css");
+ cssURLs.push("/inputex/trunk/css/inputEx.css");
+
+ SimileAjax.prefixURLs(scriptURLs, Exhibit.inputExExtension.urlPrefix + "scripts/", javascriptFiles);
+ SimileAjax.prefixURLs(cssURLs, Exhibit.inputExExtension.urlPrefix + "styles/", cssFiles);
+
+ /*for (var i = 0; i < Exhibit.locales.length; i++) {
+ scriptURLs.push(Exhibit.inputExExtension.urlPrefix + "locales/" + Exhibit.locales[i] + "/map-locale.js");
+ };*/
+
+ SimileAjax.includeJavascriptFiles(document, "", scriptURLs);
+ SimileAjax.includeCssFiles(document, "", cssURLs);
+})();
View
155 scripts/editor.js
@@ -0,0 +1,155 @@
+Exhibit.Lens.prototype._constructDefaultUI = function(itemID, div, uiContext) {
+ var database = uiContext.getDatabase();
+
+ if (Exhibit.Lens._commonProperties == null) {
+ Exhibit.Lens._commonProperties = database.getAllProperties();
+ }
+ var properties = Exhibit.Lens._commonProperties;
+
+ var label = database.getObject(itemID, "label");
+ label = label != null ? label : itemID;
+
+ if (Exhibit.params.safe) {
+ label = Exhibit.Formatter.encodeAngleBrackets(label);
+ }
+
+ var template = {
+ elmt: div,
+ className: "exhibit-lens",
+ children: [
+ { tag: "div",
+ className: "exhibit-lens-title",
+ title: label,
+ children: [
+ label + " (",
+ { tag: "a",
+ href: Exhibit.Persistence.getItemLink(itemID),
+ target: "_blank",
+ children: [ Exhibit.l10n.itemLinkLabel ]
+ },
+ ")"
+ ]
+ },
+ { tag: "div",
+ className: "exhibit-lens-body",
+ children: [
+ { tag: "table",
+ className: "exhibit-lens-properties",
+ field: "propertiesTable"
+ }
+ ]
+ }
+ ]
+ };
+ var dom = SimileAjax.DOM.createDOMFromTemplate(template);
+
+ div.setAttribute("ex:itemID", itemID);
+ //Exhibit.ToolboxWidget.createFromDOM(div, div, uiContext);
+
+ var pairs = Exhibit.ViewPanel.getPropertyValuesPairs(itemID, properties, database);
+
+ /**
+ * Retrieve inputEx customization
+ */
+ var itemType = null;
+ for (var j = 0; j < pairs.length; j++) {
+ var pair = pairs[j];
+ if(pair.propertyLabel == "type") {
+ itemType = pair.values[0];
+ break;
+ }
+ }
+ var inputExCustomization = database._types[itemType]._custom.inputEx;
+
+
+ for (j = 0; j < pairs.length; j++) {
+ var pair = pairs[j];
+
+ var tr = dom.propertiesTable.insertRow(j);
+ tr.className = "exhibit-lens-property";
+
+ var tdName = tr.insertCell(0);
+ tdName.className = "exhibit-lens-property-name";
+ tdName.innerHTML = pair.propertyLabel + ": ";
+
+ var tdValues = tr.insertCell(1);
+ tdValues.className = "exhibit-lens-property-values";
+
+ if (pair.valueType == "item") {
+ for (var m = 0; m < pair.values.length; m++) {
+ if (m > 0) {
+ tdValues.appendChild(document.createTextNode(", "));
+ }
+ tdValues.appendChild(Exhibit.UI.makeItemSpan(pair.values[m], null, uiContext));
+ }
+ } else {
+ for (var m = 0; m < pair.values.length; m++) {
+ if (m > 0) {
+ tdValues.appendChild(document.createTextNode(", "));
+ }
+
+ // Replace Exhibit.UI.makeValueSpan by inputEx inPlaceEdit (except for type property)
+ if(pair.propertyLabel == "type") {
+ tdValues.appendChild(Exhibit.UI.makeValueSpan(pair.values[m], pair.valueType));
+ }
+ else {
+
+ var editorField = null;
+
+ // Get the editor from the custom config
+ if(inputExCustomization && inputExCustomization.hasOwnProperty(pair.propertyLabel) ) {
+ editorField = inputExCustomization[pair.propertyLabel];
+ }
+ // Try to guess the editor from pair.valueType
+ else {
+ var inputExType = null;
+ if(pair.valueType == "text") {
+ inputExType = "string";
+ }
+ else if(pair.valueType == "url") {
+ inputExType = "url";
+ }
+ else {
+ console.log("Exhibit pair type not known: ",pair.valueType);
+ inputExType = "string";
+ }
+
+ var editorField = {type:inputExType, inputParams: {} };
+ }
+
+ var f = new YAHOO.inputEx.InPlaceEdit({
+ parentEl: tdValues,
+ editorField: editorField,
+ animColors:{from:"#FFFF99" , to:"#DDDDFF"},
+ value: pair.values[m]
+ });
+
+ f._exhibit = {
+ itemID: itemID,
+ properties: properties,
+ database: database ,
+ propertyLabel: pair.propertyLabel
+ };
+
+ f.updatedEvt.subscribe(Exhibit.inputExExtension.onChange);
+ }
+
+ }
+ }
+ }
+};
+
+/**
+ * Called when a value has been edited
+ */
+Exhibit.inputExExtension.onChange = function(e,params) {
+ var newValue = params[0];
+ var field = params[1];
+
+ console.log(newValue);
+ console.log(field._exhibit);
+
+};
+
+
+
View
3  styles/editor.css
@@ -0,0 +1,3 @@
+div.inputEx-InPlaceEdit-visu {
+ padding: 0;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.