platform/plugins/Streams/web/js/tools/labels.js - Q Platform
Show:

File: platform/plugins/Streams/web/js/tools/labels.js

  1. (function (Q, $, window, undefined) {
  2.  
  3. var Streams = Q.Streams;
  4. var Users = Q.Users;
  5.  
  6. /**
  7. * @module Streams-tools
  8. */
  9.  
  10. /**
  11. * Renders an interface to edit labels
  12. * @class Streams labels
  13. * @constructor
  14. * @param {Object} [options] any options for the tool
  15. * @param {Q.Event} [options.prefix='Users/'] When the user selects a contact
  16. * @param {Q.Event} [options.onSelect] When the user selects a contact
  17. */
  18. Q.Tool.define("Streams/labels", function(options) {
  19.  
  20. var tool = this;
  21. var state = tool.state;
  22. var publisherId = state.publisherId || Users.loggedInUserId();
  23. if (!state.prefix || state.prefix.substr(-1) !== '/') {
  24. throw new Q.Error("Streams/labels: prefix must end in a slash");
  25. }
  26. if (!publisherId) {
  27. throw new Q.Error("Streams/labels: publisherId is empty");
  28. }
  29. Q.Tool.setUpElement('div', 'Streams/related', {
  30. publisherId: options.publisherId,
  31. streamName: 'Streams/labels',
  32. relationType: 'labels',
  33. tag: 'div',
  34. isCategory: true,
  35. creatable: 'Streams/label'
  36. });
  37.  
  38. },
  39.  
  40. {
  41. onSelect: new Q.Event()
  42. },
  43.  
  44. {
  45. refresh: function (stream, onLoad) {
  46. var tpl = (state.editable !== false || stream.testWriteLevel('suggest'))
  47. ? 'edit'
  48. : 'view';
  49. Q.Template.render(
  50. 'Streams/image/preview/'+tpl,
  51. fields,
  52. function (err, html) {
  53. if (err) return;
  54. },
  55. state.templates[tpl]
  56. );
  57. }
  58. }
  59.  
  60. );
  61.  
  62. Q.Template.set('Streams/contacts/contact/view',
  63. '<div class="Streams_preview_container Streams_preview_view Q_clearfix">'
  64. + '<img alt="{{alt}}" class="Streams_image_preview_icon">'
  65. + '<div class="Streams_image_preview_title {{titleClass}}">'
  66. + '{{#if showTitle}}'
  67. + '<{{titleTag}} class="Streams_preview_title">{{title}}</{{titleTag}}>'
  68. + '{{/if}}'
  69. + '</div></div>'
  70. );
  71.  
  72. })(Q, jQuery, window);