27 function PropertiesPerspective(options) {
28 let oldCallback = options.callback || function() {};
29 this.vsplitbar = 'WŁAŚCIWOŚCI';
31 options.callback = function() {
34 self.$pane = $("#side-properties");
36 $(document).on('click', '[x-node]', function(e) {
41 self.$pane.on('click', '#parents li', function(e) {
42 self.edit($(this).data('node'));
45 self.$pane.on('change', '.form-control', function() {
48 if ($input.data("edited")) {
49 $input.data("edited").text($input.val());
54 element: self.$edited[0],
55 success: function(xml) {
57 let $xmlelem = $($.parseXML(xml));
59 $xmlelem.contents().attr($input.data('property'), $input.val());
61 let newxml = (new XMLSerializer()).serializeToString($xmlelem[0]);
65 base: self.doc.getBase(),
66 success: function(html) {
67 let htmlElem = $(html);
68 self.$edited.replaceWith(htmlElem);
73 error: function(e) {console.log(e);},
78 oldCallback.call(this);
81 $.wiki.SidebarPerspective.call(this, options);
84 PropertiesPerspective.prototype = new $.wiki.SidebarPerspective();
86 PropertiesPerspective.prototype.edit = function(element) {
89 let $node = $(element);
90 $("#parents", self.$pane).empty();
91 $node.parents('[x-node]').each(function() {
92 let a = $("<li class='breadcrumb-item'>").text($(this).attr('x-node'));
94 $("#parents", self.$pane).prepend(a)
97 node = $(element).attr('x-node');
98 $("h1", self.$pane).text(node);
100 $f = $("#properties-form", self.$pane);
102 self.$edited = $(element);
104 let nodeDef = elementDefs[node];
105 if (nodeDef && nodeDef.attributes) {
106 $.each(nodeDef.attributes, function(i, a) {
107 self.addEditField(a.name, a.type, $(element).attr('data-wlf-' + a.name)); // ...
112 // Only utwor can has matadata now.
113 if (node == 'utwor') {
114 // Let's find all the metadata.
115 $("> .RDF > .Description > [x-node]", $node).each(function() {
118 $meta.attr('x-node'),
127 PropertiesPerspective.prototype.addEditField = function(name, type, value, elem) {
129 let $form = $("#properties-form", self.$pane);
131 let $fg = $("<div class='form-group'>");
132 $("<label/>").attr("for", "property-" + name).text(name).appendTo($fg);
134 if (type == 'text') {
135 $input = $("<textarea>");
137 $input = $("<input>")
140 $input.addClass("form-control").attr("id", "property-" + name).data("property", name).val(value);
142 $input.data("edited", elem);
144 $input.appendTo($fg);
149 $.wiki.PropertiesPerspective = PropertiesPerspective;