Remoto - VFS: listing.js Source File
Remoto - VFS
listing.js
Go to the documentation of this file.
1 
2 define( [ 'remoto!stdlib:js/panes/pane.js',
3  'remoto!stdlib:js/widgets/widgetFactory.js',
4  'include/modal/modal',
5  'remoto!stdlib:js/include/objectRegistry.js',
6  'remoto!stdlib:js/include/preferences.js',
7  'remoto!stdlib:js/include/utils.js',
8  'remoto!stdlib:js/panes/panes/listing.css',
9  ],
11  {
12  'use strict';
13 
32  listing.prototype = new pane;
33  function listing(layout)
34  {
35  pane.call(this, layout);
36 
37  if (!layout) return;
38 
39  this._saveFields = {};
40 
41  if ("showLabels" in layout)
42  this._saveFields.showLabels = "_showLabels";
43 
44  this._entries = {};
45  this._formJq = null;
46  this._showLabels = ("showLabels" in layout) ? layout.showLabels : true;
47 
48  this._type = "listing";
49  }
50 
60  listing.prototype.createHTML = function()
61  {
62  if (this._html) return this._html;
63 
64  pane.prototype.createHTML.call(this);
65 
66  this._formJq = $("<div class='listing'>").appendTo(this._content);
67 
68  this._content.parent().css("background","var(--BG2)");
69 
70  return this._html;
71  }
72 
73  /*
74  listing.prototype.applySubscription = function(data,metadata)
75  {
76  //console.log("listing applySubscription!");
77 
78  if (this._subscribed)
79  return;
80 
81  this._subscribed = true;
82 
83  return this.applyDiff(data);
84  }
85  */
86 
97  listing.prototype.applyDiff = function(diff,user)
98  {
99  //console.log("apply diff!",arguments);
100  //console.log(arguments);
101 
102  var k = Object.keys(diff);
103  k.sort( function(a,b) {
104  var aa = diff[a].index || 0;
105  var bb = diff[b].index || 0;
106  if (aa > bb) return 1;
107  if (aa < bb) return -1;
108  return 0;
109  } );
110 
111  var d,e,m;
112  //for (e in diff)
113  for (var i=0;i<k.length;i++)
114  {
115  e = k[i];
116 
117  d = diff[e];
118  if (e in this._entries)
119  {
120  if (d === null)
121  {
122  //console.warn("Delete listing entry here!");
123  m = this._entries[e];
124  delete this._entries[e];
125  m.destroy();
126  this._formJq.find( "[buttonID="+e+"]" ).remove();
127  }
128  else
129  {
130  console.warn("Update listing here!");
131  console.warn("Need to update button properties here!");
132  console.log(d);
133  }
134  }
135  else
136  {
137  m = this.createMenuButton( e,d );
138 
139  if (m)
140  {
141  var b = m.createHTML().find("button");
142  b.find("img").removeAttr("height");//.css("min-height","45px");
143  b.attr("buttonID",e);
144 
145  this._entries[e] = m;
146  this._formJq.append( b );
147  m.activate();
148  }
149  else
150  {
151  console.error(d);
152  throw "Bad Widget: "+e;
153  }
154  }
155  }
156  }
157 
167  listing.prototype.applySettings = function(settings)
168  {
169  //FIXME: uncomment this: it's being called when applications are being opened!
170  //console.log("apply settings");
171  //console.trace(arguments);
172  }
173 
184  listing.prototype.applyMetadata = function(id,metadata)
185  {
186  //console.log("apply metadata!");
187  //console.log(arguments);
188 
189  //id = utils.cleanPath(id);
190  var id2 = id.slice( utils.cleanPath(this._path).length+1 );
191 
192  var e = this._entries[id2];
193 
194  if (e)
195  {
196  //console.log(e);
197  //console.log(metadata);
198 
199  if ("icon" in metadata) e.setIcon( metadata.icon );
200  else console.warn("Received metadata for "+id+" that doesn't include an icon...");
201 
202  if ("colorchip" in metadata) e.setColorchip( metadata.colorchip );
203 
204  utils.copyObject( metadata, e._options.metadata );
205 
206  if (e._options.metadata.action)
207  e.enable();
208  }
209  else
210  { console.warn("Received metadata for unknown path: "+id+" "+id2);
211  console.log(this._entries);
212  }
213  }
214 
226  listing.prototype.createMenuButton = function( path,entry )
227  {
228  var enabled = true;
229 
230  if (typeof(entry) == "boolean")
231  { entry = { name:path, path:path, metadata:{ icon:'js/include/loader/loader-spin.svg' } };
232  //enabled = false;
233  //console.log("metadata: "+this._path+"/"+path);
234  objectRegistry.metadataPath( this._path+"/"+path, this );
235  // var PPP = this._path+"/"+path;
236  // var THIS = this;
237  // setTimeout( function() {
238  // objectRegistry.metadataPath( PPP, THIS );
239  // }, 2000);
240  }
241 
242  var e = entry;
243  e.metadata = e.metadata || {};
244  // e.metadata.applicationPath = path;
245 
246  //console.log(e.metadata);
247 
248  if (!e.metadata.action)
249  enabled = false;
250 
251  var d = {
252  variable: path,
253  type: "button",
254  value: e.value || e.name,
255  label: e.name,
256  tip: e.name,
257  options: {
258  showLabel: this._showLabels,// || e.showLabel,
259  icon: e.metadata.icon,
260  colorchip: e.metadata.colorchip,
261  enabled: enabled,
262  metadata: e.metadata, //as an option, so it can be updated if a metadata call is needed.
263  },
264  change: this.clickMenuButton.bind(this),
265  default: null,
266  }
267 
268  var b = widgetFactory( d );
269 
270  return b;
271  }
272 
284  listing.prototype.clickMenuButton = function(variable,value,button)
285  {
286  //console.log(arguments);
287 
288  var metadata = utils.copyObject( button._options.metadata );
289  //console.log(button);
290 
291  var context = metadata.context || {};
292  delete metadata.context;
293  //context.applicationPath = metadata.applicationPath;
294  //context.sourcefile = utils.fileNameFromPath( value, true );
295  context.sourcefile = value;
296  context.sourcepath = this._path;
297  context.settingspath = preferences.fetch("settingsPath");
298 
299  for (var m in metadata)
300  context[m] = metadata[m];
301 
303  //console.log(metadata);
304 
305  switch(metadata.action.type)
306  {
307  case "openFile": this.openFile(value,metadata); break;
308 
309  case "openLayout": this.openLayout("openLayout",this._path+"/"+value,metadata); break;
310 
311  //case "openPane": metadata.template = metadata.template || {};
312  // metadata.template["openPane"] =
313  // this.openLayout("openPane",this._path+
314 
315  case "openModal": metadata.where = "modal";
316  //metadata.context = context;
317  metadata.template = metadata.template || {};
318  //metadata.template["modal"] = { path:metadata.action.path, title:metadata.action.title, size:metadata.action.size };
319  metadata.template["modal"] = metadata.action;
320  //metadata.context = context;
321  this.openLayout("modal",this._path+"/"+value,metadata);
322  break;
323 
324  case "openModalForm": metadata.where = "modalForm";
325  //var template = { name:value, path:metadata.action.path, form:metadata.action.form, type:"pane", title:metadata.action.title, size:metadata.action.size };
326  this._formJq.trigger( "openApplicationLayout", [ null, metadata.action, metadata ] );
327  break;
328 
329  default: console.error("Unknown listing action.type: "+metadata.action.type);
330  }
331  }
332 
343  listing.prototype.openFile = function(path,metadata)
344  {
345  var options = metadata.action.options;
346 
347  //console.log(metadata);
348  console.log(this._path+"/"+path+metadata.action.base);
349 
350  console.warn("listing.openFile is defunct until choosePath (and remoto!... are sorted");
351  return;
352 
353  var w = choosePath.getModal(options.what, this._path+"/"+path+metadata.action.base, options.allowed, options.sourceOrDestination, options.header );
354 
355  modal.exec( w,{ accept: (function(p) {
356  this.openLayout("openFile",path,metadata)
357  }).bind(this),
358  dismiss: null,
359  } );
360  }
361 
373  listing.prototype.openLayout = function(layoutName,path,metadata)
374  {
375  //console.log(arguments);
376 
377  var context = metadata.context || {};
378  //context.sourcefile = p.substring( p.lastIndexOf("/") );
379  //context.applicationPath = metadata.applicationPath;
380  context.sourcefile = utils.fileNameFromPath( path, true );
381  context.sourcepath = path;
382 
383  metadata.sourcepane = this; //for when 'where' is relative, like 'nearest'
384 
385  if (metadata.template[ layoutName ])
386  this._formJq.trigger( "openApplicationLayout", [ context, metadata.template[ layoutName ], metadata ] );
387  else
388  { modal.alert( "Cannot open missing template: "+layoutName );
389  console.log(metadata);
390  }
391  }
392 
401  listing.prototype.destroy = function()
402  {
403  for (var b in this._entries)
404  this._entries[b].destroy();
405 
406  this._entries = null;
407  this._formJq = null;
408 
409  pane.prototype.destroy.call(this);
410  }
411 
412  return listing;
413  }
414 );
415 
openLayout(layoutName, path, metadata)
createMenuButton(path, entry)
Open a modal to select a path from the VFS.
getModal(selectWhat, previousPath, baseDirectory, allowedTypes, sourceOrDestination, header)
setter value
a setter DOCME
getter id
returns the number of milliseconds since midnight January 1, 1970 UTC
setter user
a setter DOCME
applySettings(settings)
openFile(path, metadata)
listing(layout)
openLayout(layoutName, path, metadata)
applyMetadata(id, metadata)
applyDiff(diff, user)
clickMenuButton(variable, value, button)
createMenuButton(path, entry)
setter name
a setter DOCME
setter type
a setter DOCME
clickMenuButton()
metadataPath(id, o)
Request metadata for a given path.
Create a pane which will be mounted into a paneManager layout.
destroy()
DOCME.
createHTML()
pane(layout, object)
getter path
a getter DOCME
fetch(v, _default)
Utility functions for javascript clients.
cleanPath(path)
Clean and normalize a resource path.
fileNameFromPath(p, orDirIfNeeded)
Retrieve the last part of a file path.
copyObject(source, dest)
Create a deep copy of a JSON object, extending the destination object recursively.
resolveContextValues(o, ctx)
Recursively resolve any context values in an object.
metadata(paths)
A factory and registry for loaded widget definitions.
widgetFactory(d)
Create a widget, if possible, or return a widgetLoader.
getter enabled
Return true or false based on _enabled state.