How to use term method in pact-foundation-pact

Best JavaScript code snippet using pact-foundation-pact

term.js

Source:term.js Github

copy

Full Screen

1define(2['rmc_backbone', 'ext/underscore', 'ext/jquery', 'course', 'jquery.slide',3 'user_course', 'util', 'work_queue'],4function(RmcBackbone, _, $, _course, jqSlide, _user_course, _util) {5 var TermModel = RmcBackbone.Model.extend({6 defaults: {7 'id': '2012_09',8 'name': 'Fall 2012',9 'program_year_id': '3A',10 'course_ids': []11 },12 referenceFields: {13 'courses': ['course_ids', _course.CourseCollection]14 }15 });16 var TermView = RmcBackbone.View.extend({17 className: 'term',18 initialize: function(options) {19 this.termModel = options.termModel;20 this.courses = this.termModel.get('courses');21 this.courseCollectionView = new _course.CourseCollectionView({22 courses: this.courses,23 canShowAddReview: pageData.ownProfile24 });25 var savedExpanded = _util.getLocalData(this.getTermExpandedKey());26 this.expand = savedExpanded == null ? options.expand : savedExpanded;27 this.hasBeenExpanded = false;28 },29 render: function(options) {30 var attributes = this.termModel.toJSON();31 attributes.expand = this.expand;32 this.$el.html(33 _.template($('#term-tpl').html(), attributes));34 if (this.expand && !this.hasBeenExpanded) {35 this.hasBeenExpanded = true;36 this.$el.find('.course-collection-placeholder').replaceWith(37 this.courseCollectionView.render().el);38 }39 if (!this.expand) {40 this.$('.course-collection').addClass('hide-initial');41 }42 return this;43 },44 addCourse: function(course) {45 this.courseCollectionView.addCourse(course);46 },47 getTermExpandedKey: function() {48 return 'termExpanded:' + this.termModel.get('id');49 },50 events: {51 'click .term-name': 'toggleTermVisibility',52 'expand': 'expandTerm'53 },54 // TODO(mack): remove duplicate with similar logic in CourseView55 toggleTermVisibility: function(evt) {56 var termVisible = this.$('.course-collection').is(':visible');57 if (termVisible) {58 this.collapseTerm(evt);59 } else {60 this.expandTerm(evt);61 }62 _util.storeLocalData(this.getTermExpandedKey(), !termVisible);63 },64 expandTerm: function(evt) {65 if (!this.hasBeenExpanded) {66 this.expand = true;67 this.render();68 }69 this.$('.course-collection').fancySlide('down')70 .end().find('.term-name .arrow')71 .removeClass('icon-caret-right')72 .addClass('icon-caret-down');73 // TODO(david): Make this fn automatically called on show of courses74 this.courseCollectionView.onShow();75 },76 collapseTerm: function(evt) {77 this.expand = false;78 this.$('.course-collection').fancySlide('up')79 .end().find('.term-name .arrow')80 .removeClass('icon-caret-down')81 .addClass('icon-caret-right');82 }83 });84 var TermCollection = RmcBackbone.Collection.extend({85 model: TermModel86 });87 var TermCollectionView = RmcBackbone.View.extend({88 tagName: 'ol',89 className: 'term-collection',90 initialize: function(attributes) {91 this.termCollection = attributes.termCollection;92 this.termViews = [];93 },94 render: function() {95 this.$el.empty();96 this.termCollection.each(function(termModel, idx) {97 var expand = idx < 3;98 var termView = new TermView({99 tagName: 'li',100 termModel: termModel,101 expand: expand102 });103 this.$el.append(termView.render().el);104 this.termViews.push(termView);105 }, this);106 return this;107 },108 addTerm: function(term) {109 var termView = new TermView({110 termModel: term,111 tagName: 'li',112 expand: true113 });114 this.$el.prepend(termView.render().el);115 this.termViews.push(termView);116 },117 get: function(term_id) {118 return this.termViews.find(function(term) {119 return term.termModel.id === term_id;120 });121 }122 });123 var AddTermBtnView = RmcBackbone.View.extend({124 className: 'add-term-btn',125 initialize: function() {126 this.template = _.template($('#add-term-btn-tpl').html());127 },128 render: function() {129 this.$el.html(this.template({}));130 return this;131 },132 events: {133 'click': 'onAddTermBtnClick'134 },135 onAddTermBtnClick: function() {136 $('.schedule-input-modal').modal(); // TODO(david): This is a hack137 }138 });139 var ProfileTermsView = RmcBackbone.View.extend({140 className: 'profile-terms',141 initialize: function(options) {142 this.termCollection = options.termCollection;143 this.termCollectionView = new TermCollectionView({144 termCollection: this.termCollection145 });146 if (options.showAddTerm) {147 this.addTermBtnView = new AddTermBtnView();148 }149 this.template = _.template($('#profile-terms-tpl').html());150 },151 addToShortlist: function(course) {152 var term = this.termCollectionView.get('9999_99');153 if (!term) {154 // make shortlist if it does not exist155 var shortlistModel = new TermModel({156 'course_ids': [],157 'program_year_id': 'None',158 'id': '9999_99',159 'name': 'Shortlist'160 });161 this.termCollectionView.addTerm(shortlistModel);162 term = this.termCollectionView.get('9999_99');163 }164 term.addCourse(course, '9999_99');165 },166 events: {167 'autoScroll': 'scrollToNextCourseDelayed'168 },169 scrollToNextCourseDelayed: function(event, course) {170 setTimeout(_.bind(this.scrollToNextCourse, this, event, course), 400);171 },172 scrollToNextCourse: function(event, course) {173 // Get the list of courses, in displayed order, after the current course174 var courses = this.termCollection.reduce(function(list, term) {175 return list.concat(term.get('courses').models);176 }, []);177 var remainingCourses = _.rest(courses, _.indexOf(courses, course) + 1);178 // Find the first non-filled-in course (to scroll to)179 var targetCourse = _.find(remainingCourses, function(remCourse) {180 return !remCourse.get('user_course').isMostlyFilledIn();181 });182 if (!targetCourse) {183 return;184 }185 // Expand the course card186 var userCourseId = targetCourse.get('user_course').get('id');187 $('#' + 'course-view-' + userCourseId).trigger('expand');188 // Scroll!189 _util.scrollToElementId(userCourseId);190 mixpanel.track('Reviewing: Auto scroll', { course_id: course.get('id') });191 },192 render: function() {193 this.$el.html(this.template({}));194 if (this.addTermBtnView) {195 this.$('.add-term-btn-placeholder')196 .replaceWith(this.addTermBtnView.render().el);197 }198 this.$('.term-collection-placeholder')199 .replaceWith(this.termCollectionView.render().el);200 return this;201 }202 });203 return {204 TermModel: TermModel,205 TermView: TermView,206 TermCollection: TermCollection,207 TermCollectionView: TermCollectionView,208 ProfileTermsView: ProfileTermsView209 };...

Full Screen

Full Screen

updateWeight.js

Source:updateWeight.js Github

copy

Full Screen

1/**2 * @file js for changing weights of terms with Up and Down arrows3 */4(function ($) {5//object to store weights (tid => weight)6var termWeightsData = new Object();7Drupal.behaviors.TaxonomyManagerWeights = {8 attach: function(context, settings) {9 var weightSettings = settings.updateWeight || [];10 if (!$('#edit-toolbar.tm-weights-processed').length) {11 $('#edit-toolbar').addClass('tm-weights-processed');12 termWeightsData['form_token'] = $('input[name=form_token]').val();13 termWeightsData['form_id'] = $('input[name=form_id]').val();14 termWeightsData['weights'] = new Object();15 Drupal.attachUpdateWeightToolbar(weightSettings['up'], weightSettings['down']);16 Drupal.attachUpdateWeightTerms();17 }18 }19}20/**21 * adds click events for Up and Down buttons in the toolbar, which22 * allow the moving of selected (can be more) terms23 */24Drupal.attachUpdateWeightToolbar = function(upButton, downButton) {25 var selected;26 var url = Drupal.settings.updateWeight['url'];27 $('#'+ upButton).click(function() {28 selected = Drupal.getSelectedTerms();29 for (var i=0; i < selected.length; i++) {30 var upTerm = selected[i];31 var downTerm = $(upTerm).prev();32 Drupal.orderTerms(upTerm, downTerm);33 }34 if (selected.length > 0) {35 $.post(url, termWeightsData);36 }37 });38 $('#'+ downButton).click(function() {39 selected = Drupal.getSelectedTerms();40 for (var i=selected.length-1; i >= 0; i--) {41 var downTerm = selected[i];42 var upTerm = $(downTerm).next();43 Drupal.orderTerms(upTerm, downTerm);44 }45 if (selected.length > 0) {46 $.post(url, termWeightsData);47 }48 });49}50/**51 * adds small up and down arrows to each term52 * arrows get displayed on mouseover53 */54Drupal.attachUpdateWeightTerms = function(parent, currentIndex) {55 var settings = Drupal.settings.updateWeight || [];56 var disable = settings['disable_mouseover'];57 if (!disable) {58 var url = Drupal.settings.updateWeight['url'];59 var termLineClass = 'div.term-line';60 var termUpClass = 'img.term-up';61 var termDownClass = 'img.term-down';62 if (parent && currentIndex) {63 parent = $(parent).slice(currentIndex);64 }65 if (parent) {66 termLineClass = $(parent).find(termLineClass);67 termUpClass = $(parent).find(termUpClass);68 termDownClass = $(parent).find(termDownClass);69 }70 $(termLineClass).mouseover(function() {71 $(this).find('div.term-operations').show();72 });73 $(termLineClass).mouseout(function() {74 $(this).find('div.term-operations').hide();75 });76 $(termUpClass).click(function() {77 var upTerm = $(this).parents("li").eq(0);78 var downTerm = $(upTerm).prev();79 Drupal.orderTerms(upTerm, downTerm);80 $.post(url, termWeightsData);81 $(downTerm).find(termLineClass).unbind('mouseover');82 setTimeout(function() {83 $(upTerm).find('div.term-operations').hide();84 $(downTerm).find(termLineClass).mouseover(function() {85 $(this).find('div.term-operations').show();86 });87 }, 1500);88 });89 $(termDownClass).click(function() {90 var downTerm = $(this).parents("li").eq(0);91 var upTerm = $(downTerm).next();92 Drupal.orderTerms(upTerm, downTerm);93 $.post(url, termWeightsData);94 $(upTerm).find(termLineClass).unbind('mouseover');95 setTimeout(function() {96 $(downTerm).find('div.term-operations').hide();97 $(upTerm).find(termLineClass).mouseover(function() {98 $(this).find('div.term-operations').show();99 });100 }, 1500);101 });102 }103}104/**105 * return array of selected terms106 */107Drupal.getSelectedTerms = function() {108 var terms = new Array();109 $('.treeview').find("input:checked").each(function() {110 var term = $(this).parents("li").eq(0);111 terms.push(term);112 });113 return terms;114}115/**116 * reorders terms117 * - swap list elements in DOM118 * - post updated weights to callback in php119 * - update classes of tree view120 */121Drupal.orderTerms = function(upTerm, downTerm) {122 try {123 Drupal.getTermId(upTerm);124 Drupal.swapTerms(upTerm, downTerm);125 Drupal.swapWeights(upTerm, downTerm);126 Drupal.updateTree(upTerm, downTerm);127 } catch(e) {128 //no next item, because term to update is last child, continue129 }130}131/**132 * simple swap of two elements133 */134Drupal.swapTerms = function(upTerm, downTerm) {135 $(upTerm).after(downTerm);136 $(downTerm).before(upTerm);137}138/**139 * updating weights of swaped terms140 * if two terms have different weights, then weights are being swapped141 * else, if both have same weights, upTerm gets decreased142 *143 * if prev/next siblings of up/down terms have same weights as current144 * swapped, they have to be updated by de/increasing weight (by 1) to ensure145 * unique position of swapped terms146 */147Drupal.swapWeights = function(upTerm, downTerm) {148 var upWeight = Drupal.getWeight(upTerm);149 var downWeight = Drupal.getWeight(downTerm);150 var downTid = Drupal.getTermId(downTerm);151 var upTid = Drupal.getTermId(upTerm);152 //same weight, decrease upTerm153 if (upWeight == downWeight) {154 termWeightsData['weights'][upTid] = --upWeight;155 }156 //different weights, swap157 else {158 termWeightsData['weights'][upTid] = downWeight;159 termWeightsData['weights'][downTid] = upWeight;160 }161 //update prev siblings if necessary162 try {163 if (Drupal.getWeight($(upTerm).prev()) >= upWeight) {164 $(upTerm).prevAll().each(function() {165 var id = Drupal.getTermId(this);166 var weight = Drupal.getWeight(this);167 termWeightsData['weights'][id] = --weight;168 });169 }170 } catch(e) {171 //no prev172 }173 //update next siblings if necessary174 try {175 if (Drupal.getWeight($(downTerm).next()) <= downWeight) {176 $(downTerm).nextAll().each(function() {177 var id = Drupal.getTermId(this);178 var weight = Drupal.getWeight(this);179 termWeightsData['weights'][id] = ++weight;180 });181 }182 } catch(e) {183 //no next184 }185}186/**187 * helper to return weight of a term188 */189Drupal.getWeight = function(li) {190 var id = Drupal.getTermId(li);191 var weight;192 if (termWeightsData['weights'][id] != null) {193 weight = termWeightsData['weights'][id];194 }195 else {196 weight = $(li).find("input:hidden[class=weight-form]").attr("value");197 }198 return weight;199}...

Full Screen

Full Screen

SeismoMeta.js

Source:SeismoMeta.js Github

copy

Full Screen

1var meta = [2 {"term": "--Metadata--"},3 {"term":"_event_id"},4 {"term":"calib" },5 {"term":"channel"},6 {"term":" delta"},7 {"term":"depth_in_km"}, 8 {"term":"description"}, 9 {"term":"endtime"}, 10 {"term":"latitude"}, 11 {"term":"location"}, 12 {"term":"longitude"}, 13 {"term":"m_pp"}, 14 {"term":"m_rp"}, 15 {"term":"m_rr"}, 16 {"term":"m_rt"}, 17 {"term":"m_tp"}, 18 {"term":"m_tt"}, 19 {"term":"magnitude"},20 {"term":"mime-type"},21 {"term":" network"}, 22 {"term":"npts"}, 23 {"term":"origin_time"},24 {"term":" path"}, 25 {"term":"sampling_rate"},26 {"term":" starttime"}, 27 {"term":"station"}, 28 {"term":"type"},29 {"term": "--Parameters--"},30 {"term": "ABSORB_INSTEAD_OF_FREE_SURFACE"},31 {"term": "ANISOTROPY"},32 {"term": "ATTENUATION"},33 {"term": "CREATE_SHAKEMAP"}, 34 {"term": "DT"},35 {"term": "f0_FOR_PML"},36 {"term": "GPU_MODE"},37 {"term": "GRAVITY"},38 {"term": "HDUR_MOVIE"}, 39 {"term": "LOCAL_PATH"},40 {"term": "mesh"},41 {"term": "MODEL"},42 {"term": "MOVIE_SURFACE"},43 {"term": "MOVIE_TYPE"},44 {"term": "MOVIE_VOLUME"},45 {"term": "NGNOD"},46 {"term": "NOISE_TOMOGRAPHY"},47 {"term": "NPROC"},48 {"term": "NTSTEP_BETWEEN_FRAMES"},49 {"term": "NTSTEP_BETWEEN_OUTPUT_INFO"}, 50 {"term": "NTSTEP_BETWEEN_OUTPUT_SEISMOS"}, 51 {"term": "NTSTEP_BETWEEN_READ_ADJSRC"}, 52 {"term": "OLSEN_ATTENUATION_RATIO"}, 53 {"term": "PML_CONDITIONS"}, 54 {"term": "PML_INSTEAD_OF_FREE_SURFACE"}, 55 {"term": "PML_WIDTH_MAX"}, 56 {"term": "PML_WIDTH_MIN"}, 57 {"term": "PRINT_SOURCE_TIME_FUNCTION"}, 58 {"term": "ROTATE_PML_ACTIVATE"}, 59 {"term": "ROTATE_PML_ANGLE"}, 60 {"term": "SAVE_DISPLACEMENT"}, 61 {"term": "SAVE_FORWARD"}, 62 {"term": "SAVE_MESH_FILES"}, 63 {"term": "OCEANS"}, 64 {"term": "NSTEP"}, 65 {"term": "SIMULATION_TYPE"},66 {"term": "SUPPRESS_UTM_PROJECTION"},67 {"term": "TOMOGRAPHY_PATH"},68 {"term": "TOPOGRAPHY"},69 {"term": "USE_FORCE_POINT_SOURCE"}, 70 {"term": "USE_HIGHRES_FOR_MOVIES"}, 71 {"term": "USE_OLSEN_ATTENUATION"}, 72 {"term": "USE_RICKER_TIME_FUNCTION"}, 73 {"term": "UTM_PROJECTION_ZONE"},74 {"term": "velocity_model"}75 76 77 ];78Ext.define('RS.store.SeismoMeta', {79 extend: 'Ext.data.Store',80 model: 'RS.model.SeismoMeta',81 data: meta...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pact-foundation-pact automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful