_renderRoot: function () {

        var deferred = $.Deferred(),
            data = {},
            template;

        data = this.serializeData();
        data = this.mixinTemplateHelpers(data);

        this.triggerMethod('before:render:template');

        template = this.getTemplate();

        Marionette.Renderer.render(template, data, _.bind(function onRenderSuccess (html) {

            this.attachElContent(html);
            this.bindUIElements();

            this.triggerMethod('render:template');

            deferred.resolve();


        }, this));

        return deferred.promise();
    },
 Marionette.ItemView.prototype._renderTemplate = function() {
     var template = this.getTemplate();
 
     // Allow template-less item views
     if (template === false) {
         return;
     }
 
     if (!template) {
         throw new Marionette.Error({
             name: 'UndefinedTemplateError',
             message: 'Cannot render the template since it is null or undefined.'
         });
     }
 
     // Add in entity data and template helpers
     var data = this.getTemplateData();
     data = this.mixinTemplateHelpers(data);
 
     // Render and add to el
     var html = Marionette.Renderer.render(template, {}, this);
     this.attachElContent(html);
 
     this.binder = rivets.bind(this.el, data);
 
     return this;
 };
Example #3
0
	new Promise((onConfirm, onCancel) => {

		const modalContainer = $(Marionette.Renderer.render(confirmTemplate, {
			message,
			buttonLabel,
			modalClass: modalClass || '',
			buttonClass: buttonClass || ''
		}));

		const modal = modalContainer.find('.modal');

		modal.on('click', 'button', function() {
			if ($(this).data('action') == 'yes') {
				onConfirm();
			}
			else {
				onCancel();
			}

			modal.data('modal').trigger('hide');
		});

		$('body').append(modalContainer);
		$(ui).trigger('attach', { $el: modalContainer });
		modal.data('modal').trigger('show');
	});
Example #4
0
	new Promise((onConfirm, onCancel) => {

		const modalContainer = $(Marionette.Renderer.render(promptTemplate, {
			message,
			defaultText: defaultText || '',
			buttonLabel,
			modalClass: modalClass || '',
			buttonClass: buttonClass || '',
			blankTextError: blankTextError || ''
		}));

		const modal = modalContainer.find('.modal');

		// When clicking a button, close.
		modal.on('click', 'button', function() {

			// If it's the 'yes' button, the dialog is confirmed.
			if ($(this).data('action') == 'yes') {
				const text = modal.find('.prompt input[type="text"]').val();

				// Don't submit if a non-whitespace value is required.
				if (!text.trim() && blankTextError) {
					modal.find('.blankTextError').show().fadeIn();
					return;
				}
				onConfirm(text);
			}
			else {
				onCancel();
			}

			modal.data('modal').trigger('hide');
		});

		modal.on('submit', 'form', () => {
			modal.find('button[data-action="yes"]').click();
		});

		// Attach the modal to the body, and show it.
		$('body').append(modalContainer);
		$(ui).trigger('attach', { $el: modalContainer });
		modal.data('modal').trigger('show');

		// Put the cursor in the prompt's textbox.
		modal.find('input[type="text"]').focus()[0].setSelectionRange(
			0,
			(defaultText || '').length
		);
	});
Example #5
0
		this.parent.children.each(function(view) {
			const numMatches = view.model.numMatches(searchTerm, searchNames);

			if (numMatches !== 0) {
				passagesMatched++;

				let name = _.escape(view.model.get('name'));

				if (searchNames) {
					name = name.replace(
						searchTerm,
						'<span class="highlight">$1</span>'
					);
				}

				// we have to do a bit of a song and dance
				// to escape things correctly for the preview

				let preview = _.escape(
					view.model.get('text').replace(
						searchTerm,
						'\u3000$1\u3001'
					)
				);

				preview = preview.replace(
					/\u3000/g,
					'<span class="highlight">'
				);
				preview = preview.replace(/\u3001/g, '</span>', 'g');

				resultHtml += Marionette.Renderer.render(this.resultTemplate, {
					passageId: view.model.cid,
					passageName: name,
					numMatches,
					resultNumber: passagesMatched,
					searchPreview: preview
				});
			};
		}.bind(this));
Example #6
0
  render: function () {
    if (this.beforeRender) { this.beforeRender(); }
    this.trigger('before:render', this);
    this.trigger('item:before:render', this);
    this._refreshStyle();
    var data = this.serializeData();
    var template = this.getTemplate();
    var html = Marionette.Renderer.render(template, data);
    this.$el.html(html);

    $('#' + this.model.get('containerId')).prepend(this.$el);
    if (this.model.get('eventView')) {
      this.model.get('eventView').render(this.model.get('id'));
    }
    this.bindUIElements();

    if (this.onRender) { this.onRender(); }
    this.trigger('render', this);
    this.trigger('item:rendered', this);
    return this;

  },