define(function(require) { var template = require('rv!./board.html'); var tasksPartial = require('rv!../tasks/tasks.html'); var tasksController = require('../tasks/tasks-controller-helper'); var Ractive = require('Ractive'); var _ = require('underscore'); return Ractive.extend(_.extend({ template: template, init: function() { this.on({ removeTask: this.task.remove, addTask: this.task.add, 'dragndrop-items': function (event) { console.log(event); } }); }, partials: { tasks: tasksPartial }, data: { filterTasks: function(arr, filter) { return arr.filter(filter); } } }, tasksController)); });
define('console', function(require){ var Ractive = require('ractive'); var Console = Ractive.extend({ id: 'console', template: '#console-template', init: function() { this.on('clearLog', this.onClickClear.bind(this)); }, onClickClear: function() { this.set('messages', []); }, appendLog: function(message) { if (typeof message !== 'string') message = JSON.stringify(message, null, 4); var msg = { text: message, time: Date.now() }; this.unshift('messages', msg); this.fire('messageRendered'); }, data: { messages: [], highlightText: function(text) { return hljs.highlightAuto(text).value; }, formatDate: function (source) { return new Date(source).format(" h:mm:ss yyyy-MM-dd") } } }); //Do not want to load moment.js //http://stackoverflow.com/a/13452892/125083 Date.prototype.format = function(format) //author: meizz { var o = { "M+" : this.getMonth()+1, //month "d+" : this.getDate(), //day "h+" : this.getHours(), //hour "m+" : this.getMinutes(), //minute "s+" : this.getSeconds(), //second "q+" : Math.floor((this.getMonth()+3)/3), //quarter "S" : this.getMilliseconds() //millisecond } if(/(y+)/.test(format)) format=format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); for(var k in o)if(new RegExp("("+ k +")").test(format)) format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length)); return format; }; Ractive.components.Console = Console; return Console; });
define(function(require) { 'use strict'; var config = require('config'), Ractive = require('ractive'), layoutTemplate = require('rv!./layoutTemplate'), router = require('router'), ProfileMenu = require('components/profileMenu/profileMenu'), utilities = require('components/util/utilities'); return Ractive.extend({ template: layoutTemplate, data: { routes: router.routes, development: utilities.development, session: config.session, myProfile: false }, init: function() { this.set('myProfile', router.routes.user.active && router.routeArguments().id === config.session.userId); }, components: { 'profile-menu': ProfileMenu } }); });
onrender: function () { var MyComp = ractive.extend({ el: "comp", template: "<h1>HI hi {{name}}</h1>", data: {name: "bob"} }); myComp = new MyComp(); }
define(function(require) { var template = require('rv!./not-found.html'); var Ractive = require('Ractive'); return Ractive.extend({ template: template }); });
define(function(require) { 'use strict'; var config = require('config'), Ractive = require('ractive'), profileMenuTemplate = require('rv!./profileMenuTemplate'); return Ractive.extend({ template: profileMenuTemplate, data: { session: config.session } }); });
function todoToggleAllComponent(actions) { var component = Ractive.extend({ template: template.toString(), twoway: false, modifyArrays: false, isolate: true, toggleAll: function() { this.event.original.preventDefault(); actions.toggleAll(this.event.node.checked); } }); return component; }
define(function(require) { var template = require('rv!./task.html'); var Ractive = require('Ractive'); var tasksController = require('./tasks-controller'); var _ = require('underscore'); return Ractive.extend(_.extend({ template: template, init: function() { this.on({ save: this.task.save }); } }, tasksController)); });
function todoListComponent(actions) { var component = Ractive.extend({ twoway: false, modifyArrays: false, isolate: true, template: template.toString(), data: { list: [ ], filter: function() { return true; } }, components: { 'todo-item': todoItemComponent(actions) } }); return component; }
function todoClearDoneComponent(actions) { var component = Ractive.extend({ template: template.toString(), data: { doneNumber: 0 }, twoway: false, modifyArrays: false, isolate: true, clearDone: function() { this.event.original.preventDefault(); actions.clearDone(); } }); return component; }
define( function ( require ) { 'use strict'; var Ractive = require( 'ractive' ); var Clock = Ractive.extend({ // This is the part where we use the Ractive loader plugin - by // requiring 'rv!./clock.html', we're saying 'load the clock.html // file, but process it with the rv loader plugin'. // This means that when we use the RequireJS optimiser to bundle // all our JavaScript into a single file, the template will be parsed // before bundling so it doesn't need to happen in the browser. // // See http://requirejs.org/docs/optimization.html for more info // about the RequireJS optimiser. template: require( 'rv!./clock' ), data: { minor: new Array( 60 ), major: new Array( 12 ) }, init: function () { var self = this, interval; this.set( 'date', new Date() ); interval = setInterval( function () { self.set( 'date', new Date() ); }); this.on( 'teardown', function () { clearInterval( interval ); }); } }); return Clock; });
/** * Created by amita on 5/19/2016. */ import Ractive from 'ractive'; import Template from '../../views/user/repos-section.html'; var ReposSection = Ractive.extend({ isolated: true, template: Template // If we declare here data with attributes provided from // the template, it stops working // This is the nearest issue I found: https://github.com/ractivejs/ractive/issues/1977 /*, data: { repos: [] }*/ }); export default ReposSection;
module.exports = Ractive.extend({ template: require("./index.tpl"), CLASS: { self: "E_NewPageSectionSelector", sectionThumb: "E_SectionThumb", sectionThumbDisabled: "E_SectionThumb__disabled", clone: "E_SectionThumb--clone", cloneRemoved: "E_SectionThumb--clone__removed", cancelAddSection: "E_SectionThumb--clone__cancel", inserted: "E_SectionThumb__inserted" }, components: { }, partials: { SectionThumb: require("./SectionThumb/index.tpl") }, data: function () { return { }; }, onrender: function () { }, onconfig: function () { }, oncomplete: function () { } });
module.exports = Ractive.extend({ template: require("./index.tpl"), data: function () { return { selectedPage: null, editPage: null }; }, onconfig: function () { }, onrender: function () { this.observe("selectedPage", function (page) { if (!page || page._id === this.get("pageId")) { return; } this.loadPage(page._id); }, {init: false}); }, oncomplete: function () { this.observe("editPage", function (state) { state && console.time("pageLoaded"); }, {init: false}); }, loadPage: function (pageId) { var pageReq = this.req("page", { _id: pageId }); pageReq.then(function (page) { this.set("pageId", page._id); }.bind(this)); } });
define(function(require) { var $ = require('jquery'); var Ractive = require('ractive'); var Mustache = require('mustache'); var tooltipster = require('tooltipster'); var Utils = require('Utils'); var NccModal = require('NccModal'); var ConfirmModal = require('ConfirmModal'); var InputModal = require('InputModal'); var SettingsModal = require('SettingsModal'); var SendNemModal = require('SendNemModal'); var TransactionConfirmModal = require('TransactionConfirmModal'); var NccRactive = Ractive.extend({ el: document.body, template: '#template', components: { errorModal: NccModal, messageModal: NccModal, confirmModal: ConfirmModal, inputModal: InputModal, settingsModal: SettingsModal, sendNemModal: SendNemModal, clientInfoModal: NccModal, transactionDetailsModal: NccModal, transactionConfirmModal: TransactionConfirmModal }, computed: { allAccounts: function() { return [this.get('wallet.primaryAccount')].concat(this.get('wallet.otherAccounts')); }, appStatus: function() { switch (this.get('nccStatus.code')) { case null: case undefined: case Utils.config.STATUS_UNKNOWN: return { type: 'critical', message: this.get('texts.common.appStatus.nccUnknown') }; case Utils.config.STATUS_STOPPED: return { type: 'critical', message: this.get('texts.common.appStatus.nccUnavailable') }; case Utils.config.STATUS_STARTING: return { type: 'warning', message: this.get('texts.common.appStatus.nccStarting') }; default: // probably RUNNING switch (this.get('nisStatus.code')) { case null: case undefined: case Utils.config.STATUS_UNKNOWN: return { type: 'critical', message: this.get('texts.common.appStatus.nisUnknown') }; case Utils.config.STATUS_STOPPED: return { type: 'critical', message: this.get('texts.common.appStatus.nisUnavailable') }; case Utils.config.STATUS_STARTING: return { type: 'warning', message: this.get('texts.common.appStatus.nisStarting') }; case Utils.config.STATUS_RUNNING: if (this.get('status.booting')) { return { type: 'warning', message: this.get('texts.common.appStatus.booting') }; } else { return { type: 'warning', message: this.get('texts.common.appStatus.notBooted') }; } case Utils.config.STATUS_BOOTING: return { type: 'warning', message: this.get('texts.common.appStatus.booting') }; case Utils.config.STATUS_BOOTED: var lastBlockBehind = this.get('nis.nodeMetaData.lastBlockBehind'); if (lastBlockBehind !== 0) { if (!lastBlockBehind) { return { type: 'warning', message: this.get('texts.common.appStatus.nisInfoNotAvailable') }; } else { var daysBehind = Math.floor(this.get('nis.nodeMetaData.lastBlockBehind') / (60 * 1440)); var daysBehindText; switch (daysBehind) { case 0: daysBehindText = this.get('texts.common.appStatus.daysBehind.0'); break; case 1: daysBehindText = this.get('texts.common.appStatus.daysBehind.1'); break; default: daysBehindText = this.fill(this.get('texts.common.appStatus.daysBehind.many'), daysBehind); break; } return { type: 'warning', message: this.fill(this.get('texts.common.appStatus.synchronizing'), this.get('blockchainHeight'), daysBehindText) }; } } else { return { type: 'message', message: this.get('texts.common.appStatus.synchronized') }; } return { type: 'warning', message: this.get('texts.common.appStatus.synchronizing') }; case Utils.config.STATUS_SYNCHRONIZED: return { type: 'message', message: this.get('texts.common.appStatus.synchronized') }; } } }, nodeBooting: function() { return this.get('status.booting') || this.get('nisStatus.code') === Utils.config.STATUS_BOOTING; }, nodeBooted: function() { var nisStatus = this.get('nisStatus.code'); return nisStatus === Utils.config.STATUS_BOOTED || nisStatus === Utils.config.STATUS_SYNCHRONIZED; }, nisUnavailable: function() { return this.get('nisStatus.code') === Utils.config.STATUS_STOPPED; }, enableManualBoot: function() { return !(this.get('nisUnavailable') || this.get('nodeBooting') || this.get('nodeBooted')); }, nisSynchronized: function() { // 5 status code is not implemented yet // so we cannot completely rely on NIS status code return this.get('nisStatus.code') === Utils.config.STATUS_SYNCHRONIZED || this.get('nis.nodeMetaData.lastBlockBehind') === 0; } }, ajaxError: function(jqXHR, textStatus, errorThrown) { this.showError(textStatus, errorThrown); }, apiPath: function(api) { return '../api/' + api; }, checkSuccess: function(data, silent, settings) { var self = this; function showError(faultId, error) { if (settings && settings.altFailCb) { var noErrorModal = settings.altFailCb(faultId, error); } if (!silent && !noErrorModal) { self.showError(faultId); } return false; } if (undefined !== data.error) { switch (data.status) { case 200: break; case 601: // NODE_ALREADY_BOOTED silent = true; default: return showError(data.status); } } return true; }, syncRequest: function(url) { return $.ajax(url, { async: false, type: 'GET', error: this.ajaxError }).responseText; }, /** * @param {string} type * @param {string} api * @param {object} requestData * @param {string} success */ _ajaxRequest: function(type, api, requestData, successCb, settings, silent) { var self = this; successCb = successCb || function() {}; // set the dataType to 'text' instead of 'json' because NCC will return "" (empty string) // from void functions, but JQuery treats this as invalid JSON var s = { contentType: 'application/json', dataType: 'text', type: type, data: requestData ? JSON.stringify(requestData) : undefined, error: function (jqXHR, textStatus, errorThrown) { // first check the success (in case this is a new API) var data = jqXHR.responseText ? JSON.parse(jqXHR.responseText) : {}; if (!self.checkSuccess(data, silent, settings)) return; // since we are in an error callback, handle the error as an unknown ajax error return silent ? [] : self.ajaxError(jqXHR, textStatus, errorThrown); }, success: function(data) { // if the data is an empty string, emulate original NCC behavior by returning { ok: 1 } if (!data) { successCb({ ok: 1 }); return; } // otherwise, parse the json check the success (for legacy API handling) var parsedData = $.parseJSON(data); if (self.checkSuccess(parsedData, silent, settings)) { successCb(parsedData); } } }; $.extend(s, settings); $.ajax(this.apiPath(api), s); }, getRequest: function(api, successCb, settings, silent) { return this._ajaxRequest('get', api, undefined, successCb, settings, silent); }, postRequest: function(api, requestData, successCb, settings, silent) { return this._ajaxRequest('post', api, requestData, successCb, settings, silent); }, getModal: function(modalName) { return this.findComponent(modalName + 'Modal'); }, showError: function(errorId, message) { var modal = this.getModal('error'); if (!message && typeof errorId === 'number') { message = this.get('texts.faults.' + errorId); } modal.set({ errorId: errorId, message: message || 'Unknown error' }); modal.open(); }, showMessage: function(title, message, closeCallback) { var modal = this.getModal('message'); modal.set({ modalTitle: title, message: message }); modal.open(); if (closeCallback) { var ob = modal.observe('isActive', function(newValue, oldValue) { if (newValue === false) { closeCallback(); ob.cancel(); } }); } }, showConfirmation: function(title, message, callbacks, actions) { var modal = this.getModal('confirm'); modal.set({ modalTitle: title, message: message, callbacks: callbacks, actions: actions || [ { action: 'no', label: ncc.get('texts.modals.confirmDefault.no'), actionType: 'secondary' }, { action: 'yes', label: ncc.get('texts.modals.confirmDefault.yes'), actionType: 'primary' } ] }); modal.open(); }, showInputForm: function(title, message, fields, initValues, submitCb, submitLabel, processingLabel) { var modal = this.getModal('input'); modal.set({}); modal.set({ modalTitle: title, message: message, fields: fields, values: initValues, submitCb: submitCb, submitLabel: submitLabel, processingLabel: processingLabel }); modal.open(); }, toggleOn: function(id) { Utils.toggleOn(this, id); }, toggleOff: function(id) { Utils.toggleOff(this, id); }, fill: function(template) { // The first argument could be whether it should return the HTML decoded version if (typeof arguments[0] === 'boolean') { var decode = arguments[0]; Array.prototype.splice.call(arguments, 0, 1); template = arguments[0]; if (decode) { return Utils.htmlDecode(Mustache.render(template, arguments)); } else { return Mustache.render(template, arguments); } } else { return Mustache.render(template, arguments); } }, globalSetup: function() { require(['draggable'], function() { $('.modal').draggable({ handle: '.modal-head' }); }); }, loadPage: function(page, params, isBack, isInit) { var self = this; // We use require(string) instead of require(array, function) to make page loading process synchronous // require(string) needs dependencies to be loaded before being used // So we have to load all layout files and templates first var layouts = []; var loadLayout = function(layoutName) { require([layoutName], function(layout) { layouts.unshift(layout); require([layout.template], function() { if (layout.parent) { loadLayout(layout.parent); } else { replaceLayouts(); } }); }); }; var replaceLayouts = function() { var oldParams = ncc.get('params'); var paramsChanged = JSON.stringify(oldParams) !== JSON.stringify(params); for (var i = 0; i < layouts.length; i++) { var layout = layouts[i]; var keypath = 'layout.' + i; var currentLayout = self.get(keypath); if (!layout.alreadyInit && layout.initOnce) { layout.initOnce(); layout.alreadyInit = true; } if (paramsChanged && layout.paramsChanged) { var abort = layout.paramsChanged(params); if (abort) return; } if (!currentLayout || (currentLayout.name !== layout.name)) { var template = require(layout.template); if (currentLayout && currentLayout.leave) { $.each(currentLayout.leave, function() { this.apply(currentLayout); }); } // Init if (layout.initEverytime) { var abort = layout.initEverytime(params); if (abort) return; } self.set(keypath, null); self.partials[i] = template; self.set(keypath, layout); // Setup if (!layout.alreadySetup && layout.setupOnce) { layout.setupOnce(); layout.alreadySetup = true; } if (layout.setupEverytime) { var abort = layout.setupEverytime(params); if (abort) return; } } } self.globalSetup(); // Clear the old layouts var currLayouts = self.get('layout'); if (currLayouts && currLayouts.length) { for (; i < currLayouts.length; i++) { self.set('layout.' + i, null); } } if (!isBack) { var queryString = ''; if (params) { queryString = Utils.toQueryString(params); } else if (isInit) { queryString = location.search; params = Utils.queryStringToJson(location.search); } var url = layouts[layouts.length - 1].url + queryString; if (isInit) { history.replaceState({ page: page, params: params }, 'entry', url); } else { history.pushState({ page: page, params: params }, null, url); } } ncc.set('params', params); }; loadLayout(page); }, onrender: function(options) { var self = this; require(['languages'], function(languages) { self.set('languages', languages); self.observe('settings.language', function(newValue) { newValue = newValue || Utils.config.defaultLanguage; for (var i = 0; i < languages.length; i++) { if (languages[i].id.toLowerCase() === newValue.toLowerCase()) { self.set('texts', languages[i].texts); return; } } }); }); this.on({ redirect: function(e, page, params) { this.loadPage(page, params); }, openModal: function(e, id) { this.getModal(id).open(); }, shutdown: function() { var self = this; this.showConfirmation(ncc.get('texts.modals.shutdown.title'), ncc.get('texts.modals.shutdown.message'), { yes: function() { self.loadPage('start'); } }); }, selectFile: function(e, id) { var input = this.nodes[id]; var evt = document.createEvent("MouseEvents"); evt.initEvent('click', true, false); input.dispatchEvent(evt); }, registerToolTip: function(e) { var $node = $(e.node); if (!$node.data('tooltipster-ns') && $node.attr('title')) { $node.tooltipster({ position: 'bottom', delay: 50, functionBefore: function($origin, continueTooltip) { var title = $origin.attr('title'); if (title) { $origin.tooltipster('content', title); $origin.removeAttr('title'); } continueTooltip(); } }); $node.tooltipster('show'); } }, set: function(e, keypath, val) { this.set(keypath, val); } }); this.set('fill', this.fill); this.set('formatCurrency', Utils.formatCurrency); this.global = { $window: $(window), $document: $(document), $html: $('html'), $body: $('body') }; } }); window.ncc = new NccRactive(); return ncc; });
Ractive.components.DayView = Ractive.extend({ isolated: true, template: `<div class="fc-calendar fc-day-view fc-one-row"> <div class="fc-head text-left"> {{datetime(date, 'dddd')}} </div> <hr /> <div> {{#each days}} <h3 class="text-muted"> {{#if events.length}}{{events.length}}{{else}}No{{/if}} Events </h3> {{#each events}} <div class="panel panel-info" intro="animate:fadeIn"> <b class="text-info text-capitalize"> <i class="fa fa-fw {{#if type == 'birthday'}}fa-birthday-cake {{elseif type == 'personal'}}fa-calendar-o {{elseif type == 'work'}}fa-check{{/if}}"></i> {{type}} </b> <h3> {{title}} </h3> <a href="{{url}}" target="_blank"> <h4>{{url}}</h4> </a> </div> {{/each}} {{/each}} </div> </div>` });
import Ractive from 'ractive'; export default Ractive.extend({ template: ` <h1 class="page1">Page 1</h1> <div class="page1"> <div>App: {{parentGlobals.app}}</div> <div>id: {{routeParams.id}}</div> <div>option: {{routeParams.option}}</div> <div> <h3>routeParams</h3> <ul> {{#each routeParams}} <li>{{.}}</li> {{/each}} </ul> </div> </div> `, oninit() { console.log('Page1 init', this.get('routeParams')); }, onteardown() { console.log('Page1 teardown'); } });
var TechnologiesList = Ractive.extend({ isolated: true, template: render(template), onrender: function () { this.observe('search', function (current, old) { function filter(technology) { var name = technology.name.toLowerCase(); current = current ? current.toLowerCase() : '' return current ? !!~name.indexOf(current) : true; } var filtered = technologies.items.filter(filter); this.set('technologies', filtered); }) this.on('delete', function (ev, id, name) { ev.original.preventDefault(); confirm(t('confirmation.title'), t('admin-technologies-form.confirmation.body', {name: name})) .cancel(t('confirmation.cancel')) .ok(t('confirmation.ok')) .modal() .closable() .effect('slide') .focus() .show(onconfirmdelete.bind(this)); function onconfirmdelete(ok) { if (!ok) return; request .del('/api/technologies/' + id) .end(function (err, res) { if (err || !res.ok) return log('Found error %o', err || res.error); technologies.fetch(); page('/admin/technologies'); }); } }) } });
module.exports = Ractive.extend({ template: template, lazy: false, isolated: true, data: function() { return { text: "", value: null, placeholder: "", displayMember: null, valueMember: null, suggest: null, autoselect: false, delay: 200, _state: { text: "", value: null, suggestions: null, visible: false, isSelected: this.isSelected.bind(this), getText: this.getText.bind(this), getValue: this.getValue.bind(this) } }; }, isSelected: function(obj) { return this.getState("text") == this.getText(obj) && this.getState("value") == this.getValue(obj); }, getText: getter("displayMember"), getValue: getter("valueMember"), getSelectedIndex: function() { var suggestions = this.getState("suggestions") || []; for (var i = 0; i < suggestions.length; i++) { if (this.isSelected(suggestions[i])) return i; } return -1; }, getState: function(path) { return this.get("_state." + path); }, setState: function(path, value) { this.set("_state." + path, value); }, oninit: function() { }, onrender: function() { this.on("click", function(event) { var ul = this.find("ul"); for (var i = 0; i < ul.children.length; i++) { if (ul.children[i] == event.original.target) { this.select(i); return; } } }); this.on("keydown", function(event) { var key = event.original.keyCode; if (key == KEY_ENTER) { event.original.preventDefault(); this.show(false); this.select(this.getSelectedIndex()); } else if (key == KEY_ESC) { event.original.preventDefault(); this.cancel(); } else if (key == KEY_UP || key == KEY_DOWN) { event.original.preventDefault(); var index = this.getSelectedIndex(); if (!this.getState("visible")) { this.loadSuggestions(); this.show(true); return; } if (index == -1) this.preview(0); if (key == KEY_UP && index > 0) this.preview(index - 1); if (key == KEY_DOWN && index < this.getState("suggestions").length - 1) this.preview(index + 1); } else { this.loadSuggestions(); } }); this.on("blur", function() { if (this.blurTimer) clearTimeout(this.blurTimer); this.blurTimer = setTimeout(this.show.bind(this, false), 100); }); this.setState("text", this.get("text")); this.setState("value", this.get("value")); }, show: function(visible) { visible = visible && this.getState("suggestions") && this.getState("suggestions").length > 0; this.setState("visible", !!visible); }, cancel: function() { this.setState("text", this.get("text")); this.setState("value", this.get("value")); this.show(false); }, select: function(index, visible) { this.preview(index); this.set("text", this.getState("text")); this.set("value", this.getState("value")); this.show(!!visible); }, preview: function(index) { var suggestions = this.getState("suggestions") || []; var obj = suggestions[index]; if (obj == undefined) { var text = this.getState("text"); var value = null; } else { var text = this.getText(obj); var value = this.getValue(obj); } this.setState("text", text); this.setState("value", value); }, loadSuggestions: function() { if (this.suggestTimer) { clearTimeout(this.suggestTimer); } var timer = this.suggestTimer = setTimeout(function() { if (timer != this.suggestTimer) return; this.suggestTimer = null; var suggest = this.get("suggest"); var text = this.getState("text"); suggest(text, function(error, suggestions) { if (error) return; this.setState("suggestions", suggestions || []); this.show(document.activeElement == this.find("input")); if (this.get("autoselect")) { var text = this.getState("text"); for (var i = 0; i < suggestions.length; i++) { if (text == this.getText(suggestions[i])) { return this.select(i, this.find("input") == document.activeElement); } } } }.bind(this)); }.bind(this), this.get("delay") || 0); } });
define(function(require) { 'use strict'; var config = require('config'), Ractive = require('ractive'), userTemplate = require('rv!./userTemplate'), Layout = require('layouts/search/layout'), router = require('router'), XhrPanel = require('components/xhrPanel/xhrPanel'), ApiSequence = require('components/apiSequence/apiSequence'), $ = require('jquery'); var UserPage = Ractive.extend({ template: userTemplate, data: { from: 1, size: 10, filter: '' }, computed: { showPreviousButton: '${xhrs.from} > 1', showNextButton: '${xhrs.to} < ${xhrs.of}' }, init: function() { this.set('userId', router.routeArguments().id); this.set('myProfile', this.get('userId') === config.session.userId); $('.bs-tooltip').tooltip(); var apiSequence = new ApiSequence({ el: this.nodes['api-sequence'] }); apiSequence.set('disableTutorial', true); $.ajax('/users/' + this.get('userId')) .done(function(data) { this.set('emailMd5', data.emailMd5); this.set('displayName', data.displayName); $('.bs-tooltip').tooltip(); }.bind(this)); this.observe({ filter: function() { this.set('from', 1); this.search(); } }); this.on({ teardown: function() { apiSequence.teardown(); }, openResult: function openResult(event, item) { new XhrPanel({data: item}); }, setFrom: function(event, from) { this.set('from', from); this.search(); }, editDisplayName: function() { this.set('editDisplayName', true); }, saveDisplayName: function() { this.set('editDisplayName', false); $.ajax('/users/' + this.get('userId') + '/displayname', { type: 'PUT', contentType: 'application/json', data: JSON.stringify({ displayName: this.get('displayName') }) }) .done(function() { config.session.displayName = this.get('displayName'); }.bind(this)) .fail(function() { this.set('displayName', config.session.displayName); }.bind(this)); }, cancelEditDisplayName: function() { this.set('displayName', config.session.displayName); this.set('editDisplayName', false); } }); this.search(); }, search: function() { $.ajax('/xhr?from=' + this.get('from') + '&owner=' + this.get('userId') + '&q=' + this.get('filter').trim()) .done(function(data) { this.set('xhrs', data); }.bind(this)); } }); return Layout.extend({ components: { 'content-placeholder': UserPage } }); });
var Manager = Ractive.extend({ template: require('../templates/datacomb.hbs'), partials: { colFilter: require('../templates/col-filter.hbs'), summaryStats: require('../templates/summary-stats.hbs') }, components: { ColHeader: ColHeader, RangeSlider: RangeSlider }, // data: function() { return { sortColNdx: null, sortDesc: false, focusOnHover: true, hideUnfocused: false, filtersOpen: false, statsOpen: false, histogramsOpen: false, hoverValues: [], cols: [], filters: [], groupByColNdx: -1, colorByColNdx: -1, scatterPlotNdx: -1 }; }, // computed: { discreteCols: function() { return _.where(this.get('cols'), { type: 'discrete' }); } }, // onrender: function() { // reset filters back to initial state this.resetFilters = function(cols) { this.set('filters', cols.map(function(col) { if(col.type === 'discrete') { var toggled = {}; // build new obj with T/F values col.uniqValues.forEach(function(v) { toggled[v] = true; }); return { toggled: toggled }; } else { return { gt: col.min, lt: col.max }; } }) ); }; this.observe('cols', this.resetFilters); this.on('*.reset-filters', function() { this.resetFilters(this.get('cols')); }); } });
import Ractive from 'ractive' import Tab from './tab' import tmpl from '../../views/tabNav.html' var TabNav = Ractive.extend({ template: tmpl, data(){ return { } }, components: { tab: Tab } }) export default TabNav;
var Ractive = require('ractive'); function onrender() { console.log('Rendering subview'); } module.exports = Ractive.extend({ isolated: false, onrender: onrender, template: require('./templates/subView.html') });
var app = window.app = new Application(new RactiveLayoutManager({ rootElement: '.app1' })); app.router.map(function(match) { match("/").to("application", function(match) { match("/").to("application"); match("/posts").to("post",function(match) { match("/").to("post.index"); match("/:id").to("post.edit"); }); }); }); var ApplicationView = Ractive.extend({ el: ".app1", template: "oi<br /><div class=\"application-outlet\"></div>" }); app.router.addHandlers({ "application": { view: ApplicationView }, "post": { view: PostView }, "post.index": { view: PostIndexView }, "post.edit": { view: PostEditView, controller: null
var TagForm = Ractive.extend({ isolated: true, template: render(template), onrender: function () { var self = this; this.set('lang', language()); this.on('save', function (ev) { var tag = this.get('tag'); var url = '/api/tags/' + (tag.id || 'create'); request .post(url) .send(tag) .end(function (err, res) { if (err) { return new Panel({ classes: 'panel-danger', heading: t('panel.heading.error'), body: t('panel.heading.body'), el: self.find('.panels') }); } var panel = new Panel({ classes: 'panel-success', heading: t('panel.heading.success'), body: t('admin.tags.save.success'), el: self.find('.panels') }); tags.fetch(); }); return false; }); } });
var Ractive = require('ractive'); module.exports = Ractive.extend({ isolated: true, data: { }, computed: { }, oninit: function() { }, onrender: function() { } });
var Page = Ractive.extend(common_options_all, common_options_page_site, { isolated: true, onconstruct: function(options){ var self = this; self._super.apply(self, arguments); self.site = self.parent; self.site.page = self; self.site.Page = self.constructor; self.api = self.site.api; options.data = _.assign( {}, process.browser && self.site.useDataScript && window._page_vm_data || {}, options.data || {}, { route: self.site.router.route, Route: self.site.router.Route } ); }, onconfig: function(){ var self = this; // handle initial `Page#onroute` if (process.browser && self.site.useDataScript && window._page_vm_data){ delete window._page_vm_data; } else { self._onroute(true); } }, oninit: function(){ var self = this; if (process.browser){ // handle following `Page#onroute`s self.observe('route', function(route){ self._onroute(false); }, {init: false}); } } });
var $ = require('jquery'); var _ = require('underscore'); var Backbone = require('backbone'); var Ractive = require('ractive'); require('ractive-adaptors-backbone'); require('./controller/canvas.js'); Backbone.$ = $; var AlarmView = Ractive.extend(require("./view/alarm.html")); var SensorView = Ractive.extend(require("./view/sensor.html")); var TrendView = Ractive.extend(require("./view/trend.html")); // settings var url_api = "http://localhost:8000/katrin/default/api/sensor.json"; var cols = 4; // sensor configuration var sensorConfig = require('../../config/sensor.json'); var SensorCollection = require('./model/SensorCollection'); var sensorGroup = new SensorCollection(sensorConfig); // fetch sensor data sensorGroup.url = url_api; sensorGroup.fetch(); sensorGroup.fetch({data: {w: 600, r: 60}});
.clamp([true]); var initialState = { outerArcPath: inactiveArc({ endAngle: Math.PI * 2 }), progressArcPath: activeArc({ endAngle: 0 }) }; var CircularProgress = Ractive.extend({ template: '#progressTempl', isolated: true, twoway: false, debug: true, computed: { angle: function () { var percentThrough = this.get('percentThrough'); return percentThrough ? percentToAngle(percentThrough) : 0; } }, oninit: function () { this.set(initialState); this.observe('angle', function (angle) { arc = activeArc; this.set({ progressArcPath: arc({ endAngle: angle }) }); }); } }); module.exports = CircularProgress;
import Ractive from 'ractive'; import template from '../views/counter.html'; import navigationComponent from './navigation.js'; let counterComponent = Ractive.extend({ template: template, data() { return { options: { feature: 'feature - 1' } } }, components: { navigation: navigationComponent }, oninit() { this.set('feature', 'feature - 2'); } }); export default counterComponent;