indicatePasswordStrength: function(event) {
      var password = $('#password').val();
      var $passwordStrength = $('#passwordError');

      // Must have capital letter, numbers and lowercase letters
      var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
      // Must have either capitals and lowercase letters or lowercase and numbers
      var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
      // Must be at least 8 characters long
      var okRegex = new RegExp("(?=.{8,}).*", "g");

      if (okRegex.test(password) === false) {
        var classes = 'alert alert-error';
        var htmlText = Origin.l10n.t('app.validationlength', {length: 8});
      } else if (strongRegex.test(password)) {
        var classes = 'alert alert-success';
        var htmlText = Origin.l10n.t('app.passwordindicatorstrong');
      } else if (mediumRegex.test(password)) {
        var classes = 'alert alert-info';
        var htmlText = Origin.l10n.t('app.passwordindicatormedium');
      } else {
        var classes = 'alert alert-info';
        var htmlText = Origin.l10n.t('app.passwordindicatorweak');
      }

      $passwordStrength.removeClass().addClass(classes).html(htmlText);
    },
 onChangePasswordClicked: function() {
   var self = this;
   Origin.Notify.confirm({
     type: 'input',
     title: Origin.l10n.t('app.resetpasswordtitle'),
     text: Origin.l10n.t('app.resetpasswordinstruction', { email: this.model.get('email') }),
     inputType: 'password',
     confirmButtonText: 'Save',
     closeOnConfirm: false,
     callback: function(newPassword) {
       if(newPassword === false) return;
       else if(newPassword === "") return swal.showInputError(Origin.l10n.t('app.passwordempty'));
       var postData = {
         "email": self.model.get('email'),
         "password": newPassword
       };
       Helpers.ajax('/api/user/resetpassword', postData, 'POST', function() {
         self.model.fetch();
         Origin.Notify.alert({
           type: 'success',
           text: Origin.l10n.t('app.changepasswordtext', { email: self.model.get('email') })
         });
       });
     }
   });
 },
    addComponent: function(layout) {
      Origin.trigger('editorComponentListView:remove');

      var componentType = Origin.editor.data.componenttypes.findWhere({ name: this.model.get('name') });
      var model = new ComponentModel();

      model.save({
        title: Origin.l10n.t('app.placeholdernewcomponent'),
        displayTitle: Origin.l10n.t('app.placeholdernewcomponent'),
        body: '',
        _parentId: this._parentId,
        _courseId: Origin.editor.data.course.get('_id'),
        _type: 'component',
        _componentType: componentType.get('_id'),
        _componentTypeDisplayName: componentType.get('displayName'),
        _component: componentType.get('component'),
        _layout: layout,
        version: componentType.get('version')
      }, {
        success: _.bind(function(model) {
          var parentId = model.get('_parentId');
          Origin.trigger('editorView:addComponent:' + parentId);
          $('html').css('overflow-y', '');
          $.scrollTo('.block[data-id=' + parentId + ']');
        }, this),
        error: function() {
          $('html').css('overflow-y', '');
          Origin.Notify.alert({ type: 'error', text: Origin.l10n.t('app.erroraddingcomponent') });
        }
      });
    }
 copyIdToClipboard: function() {
   var id = this.model.get('_id');
   if(Helpers.copyStringToClipboard(id)) {
     Origin.Notify.alert({ type: 'success', text: Origin.l10n.t('app.copyidtoclipboardsuccess', { id: id }) });
     return;
   }
   Origin.Notify.alert({ type: 'warning', text: Origin.l10n.t('app.app.copyidtoclipboarderror', { id: id }) });
 },
        error: function(jqXHR, textStatus, errorThrown) {
          self.showExportAnimation(false, $btn);
          self.exporting = false;

          Origin.Notify.alert({
            type: 'error',
            title: Origin.l10n.t('app.exporterrortitle'),
            text: Origin.l10n.t('app.errorgeneric') +
              Origin.l10n.t('app.debuginfo', { message: jqXHR.responseJSON.message })
          });
        }
 error: function(model, response, options) {
   var data = { key: key, value: value };
   var errorCode = response.responseJSON && response.responseJSON.code;
   var errorMessage = response.responseText;
   switch(errorCode) {
     // duplicate key
     case 11000:
       return self.onError(Origin.l10n.t('app.duplicateuservalueerror', data));
     default:
       return self.onError(Origin.l10n.t('app.uservalueerror') + ' (' + errorMessage + ')');
   }
 }
    deleteBlockPrompt: function(event) {
      event && event.preventDefault();

      Origin.Notify.confirm({
        type: 'warning',
        title: Origin.l10n.t('app.deleteblock'),
        text: Origin.l10n.t('app.confirmdeleteblock') + '<br />' + '<br />' + Origin.l10n.t('app.confirmdeleteblockwarning'),
        callback: _.bind(function(confirmed) {
          if (confirmed) this.deleteBlock();
        }, this)
      });
    },
    copyIdToClipboard: function(model) {
      var id = model.get('_id');

      if (helpers.copyStringToClipboard(id)) {
        Origin.Notify.alert({
          type: 'info',
          text: Origin.l10n.t('app.copyidtoclipboardsuccess', { id: id })
        });
      } else {
        Origin.Notify.alert({
          type: 'warning',
          text: Origin.l10n.t('app.app.copyidtoclipboarderror', { id: id })
        });
      }
    },
    blockUserAccess: function(message, hideUI) {
      if(hideUI) {
        $('body').addClass('no-ui');
        Origin.trigger('remove:views');
      }
      var cb = hideUI ? Origin.router.navigateToLogin : Origin.router.navigateToHome;

      Origin.Notify.alert({
        type: 'error',
        title: Origin.l10n.t('app.errorpagenoaccesstitle'),
        text: message || Origin.l10n.t('app.errorpagenoaccess'),
        confirmButtonText: Origin.l10n.t('app.ok'),
        callback: cb
      });
    },
 isValid: function() {
   var email = this.$('input[name=email]').val().trim();
   var valid = Helpers.isValidEmail(email);
   if(valid) {
     this.$('.field-error').addClass('display-none');
   } else {
     this.$('.field-error').removeClass('display-none');
     Origin.Notify.alert({
       type: 'error',
       title: Origin.l10n.t('app.validationfailed'),
       text: Origin.l10n.t('app.invalidusernameoremail')
     });
   }
   return valid;
 },
 Helpers.ajax('/api/user/resetpassword', postData, 'POST', function() {
   self.model.fetch();
   Origin.Notify.alert({
     type: 'success',
     text: Origin.l10n.t('app.changepasswordtext', { email: self.model.get('email') })
   });
 });
 }, this)).fail(_.bind(function (jqXHR, textStatus, errorThrown) {
   Origin.Notify.alert({
     type: 'error',
     text: Origin.l10n.t('app.errorcopy') + (jqXHR.message ? '\n\n' + jqXHR.message : '')
   });
   this.hidePasteZones();
 }, this));
    validateInput: function () {
      var $uploadFile = this.$('.asset-file');
      var validated = true;
      var $uploadFileErrormsg = $uploadFile.prev('label').find('span.error');

      $.each(this.$('.required'), function (index, el) {
        var $errormsg = $(el).prev('label').find('span.error');
        if (!$.trim($(el).val())) {
          validated = false;
          $(el).addClass('input-error');
          $errormsg.text(Origin.l10n.t('app.pleaseentervalue'));
        } else {
          $(el).removeClass('input-error');
          $errormsg.text('');
        }
      });

      if(!$uploadFile.val()) {
        validated = false;
        $uploadFile.addClass('input-error');
        $uploadFileErrormsg.text(Origin.l10n.t('app.pleaseaddfile'));
      } else {
        $uploadFile.removeClass('input-error');
        $uploadFileErrormsg.text('');
      }

      return validated;
    },
      Origin.trigger('scaffold:updateSchemas', function() {
        Origin.Notify.alert({ type: 'success', text: Origin.l10n.t('app.uploadpluginsuccess') });

        Origin.trigger('sidebar:resetButtons');
        $('.loading').hide();

        Origin.router.navigateTo('pluginManagement/' + (data.pluginType || ''));
      }, this);
    deleteProjectPrompt: function(event) {
      event && event.preventDefault();
      if(this.model.get('_isShared') === true) {
        if(this.model.get('createdBy') === Origin.sessionModel.id){
          Origin.Notify.confirm({
            type: 'warning',
            title: Origin.l10n.t('app.deletesharedproject'),
            text: Origin.l10n.t('app.confirmdeleteproject') + '<br/><br/>' + Origin.l10n.t('app.confirmdeletesharedprojectwarning'),
            destructive: true,
            callback: _.bind(this.deleteProjectConfirm, this)
          });
        } else {
          Origin.Notify.alert({
            type: 'error',
            text: Origin.l10n.t('app.errorpermission')
          });
        }
        return;

      }
      Origin.Notify.confirm({
        type: 'warning',
        title: Origin.l10n.t('app.deleteproject'),
        text: Origin.l10n.t('app.confirmdeleteproject') + '<br/><br/>' + Origin.l10n.t('app.confirmdeleteprojectwarning'),
        callback: _.bind(this.deleteProjectConfirm, this)
      });
    },
Example #16
0
 Origin.on('origin:dataReady login:changed', function() {
   Origin.globalMenu.addItem({
     "location": "global",
     "text": Origin.l10n.t('app.assetmanagement'),
     "icon": "fa-file-image-o",
     "callbackEvent": "assetManagement:open",
     "sortOrder": 2
   });
 });
    onDeleteButtonClicked: function(event) {
      event.preventDefault();

      Origin.Notify.confirm({
        type: 'warning',
        text: Origin.l10n.t('app.assetconfirmdelete'),
        callback: _.bind(this.onDeleteConfirmed, this)
      });
    },
 onResetLoginsClicked: function() {
   var self = this;
   Origin.Notify.confirm({
     text: Origin.l10n.t('app.confirmresetlogins', { email: this.model.get('email') }),
     callback: function(confirmed) {
       if(confirmed) self.updateModel('failedLoginCount', 0);
     }
   });
 },
Example #19
0
 Origin.on('editor:extensions', function(data) {
   Origin.trigger('location:title:update', {
     breadcrumbs: ['dashboard', 'course', { title: Origin.l10n.t('app.editorextensions') }],
     title: Origin.editor.data.course.get('title')
   });
   var route1 = Origin.location.route1;
   // Check whether the user came from the page editor or menu editor
   var backButtonRoute = "#/editor/" + route1 + "/menu";
   var backButtonText = Origin.l10n.t('app.backtomenu');
   if (Origin.previousLocation.route2 === "page") {
     backButtonRoute = "#/editor/" + route1 + "/page/" + Origin.previousLocation.route3;
     backButtonText = Origin.l10n.t('app.backtopage');
   }
   Origin.sidebar.addView(new EditorExtensionsEditSidebarView().$el, {
     backButtonText: backButtonText,
     backButtonRoute: backButtonRoute
   });
   Origin.contentPane.setView(EditorExtensionsEditView, { model: new Backbone.Model({ _id: route1 }) });
 });
    onRestoreButtonClicked: function(event) {
      event.preventDefault();

      event.preventDefault();

      Origin.Notify.confirm({
        text: Origin.l10n.t('app.assetconfirmrestore'),
        callback: _.bind(this.onRestoreConfirmed, this)
      });
    },
 $.get(url, function(data, textStatus, jqXHR) {
   if (!data.success) {
     this.resetPreviewProgress();
     Origin.Notify.alert({
       type: 'error',
       text: Origin.l10n.t('app.errorgeneratingpreview') +
         Origin.l10n.t('app.debuginfo', { message: jqXHR.responseJSON.message })
     });
     previewWindow.close();
     return;
   }
   const pollUrl = data.payload && data.payload.pollUrl;
   if (pollUrl) {
     // Ping the remote URL to check if the job has been completed
     this.updatePreviewProgress(pollUrl, previewWindow);
     return;
   }
   this.updateCoursePreview(previewWindow);
   this.resetPreviewProgress();
 }.bind(this)).fail(function(jqXHR, textStatus, errorThrown) {
 $.each(this.$('.required'), function (index, el) {
   var $errormsg = $(el).prev('label').find('span.error');
   if (!$.trim($(el).val())) {
     validated = false;
     $(el).addClass('input-error');
     $errormsg.text(Origin.l10n.t('app.pleaseentervalue'));
   } else {
     $(el).removeClass('input-error');
     $errormsg.text('');
   }
 });
    showComponentList: function(event) {
      event.preventDefault();
      // If adding a new component
      // get current layoutOptions
      var layoutOptions = this.model.get('layoutOptions');

      var componentSelectModel = new Backbone.Model({
        title: Origin.l10n.t('app.addcomponent'),
        body: Origin.l10n.t('app.pleaseselectcomponent'),
        _parentId: this.model.get('_id'),
        componentTypes: Origin.editor.data.componenttypes.toJSON(),
        layoutOptions: layoutOptions
      });

      $('body').append(new EditorPageComponentListView({
        model: componentSelectModel,
        $parentElement: this.$el,
        parentView: this
      }).$el);
    },
Example #24
0
 getNearestPage(model, function(page) {
   var data = {
     model: model || {},
     page: page,
     langString: Origin.l10n.t('app.' + getLangKey())
   };
   Origin.trigger('location:title:update', {
     breadcrumbs: generateBreadcrumbs(data),
     title: getTitleForModel(data)
   });
 });
 onDeleteClicked: function() {
   var self = this;
   Origin.Notify.confirm({
     type: 'confirm',
     text: Origin.l10n.t('app.confirmdeleteuser', { email: this.model.get('email') }),
     callback: function(confirmed) {
       if(confirmed) {
         self.model.destroy({ error: self.onError });
       }
     }
   });
 },
    togglePasswordUI: function(model, showPaswordUI) {
      var formSelector = 'div.change-password-section .form-group .inner';
      var buttonSelector = '.change-password';

      if (showPaswordUI) {
        this.$(formSelector).removeClass('display-none');
        this.$(buttonSelector).text(Origin.l10n.t('app.cancel'));
      } else {
        this.$(buttonSelector).text(Origin.l10n.t('app.changepassword'));
        this.$(formSelector).addClass('display-none');

        this.$('#password').val('').removeClass('display-none');
        this.$('#passwordText').val('').addClass('display-none');
        this.$('.toggle-password i').addClass('fa-eye').removeClass('fa-eye-slash');

        this.$('.toggle-password').addClass('display-none');
        this.$('#passwordError').html('');

        this.model.set('password', '');
      }
    },
 onDeleteClicked: function(event) {
   event && event.preventDefault();
   var self = this;
   var presetName = $(event.currentTarget).closest('.preset').attr('data-name');
   Origin.Notify.confirm({
     text: Origin.l10n.t('app.presetdeletetext', { preset: presetName }),
     callback: function(confirmed) {
       if (!confirmed) return;
       Origin.trigger('managePresets:delete', presetName);
       self.render();
     }
   });
 }
 verifyRoute: function(module, route1) {
   // Check this user has permissions
   if(!Origin.permissions.checkRoute(Backbone.history.fragment)) {
     this.blockUserAccess();
     return false;
   }
   // FIXME routes shouldn't be hard-coded
   if(!this.isUserAuthenticated()  && (module !== 'user' && route1 !== 'login')) {
     this.blockUserAccess(Origin.l10n.t('app.errorsessionexpired'), true);
     return false;
   }
   return true;
 },
      $.get(url, function(data, textStatus, jqXHR) {
        if (!data.success) {
          Origin.Notify.alert({
            type: 'error',
            text: Origin.l10n.t('app.errorgeneric') +
              Origin.l10n.t('app.debuginfo', { message: jqXHR.responseJSON.message })
          });
          this.resetDownloadProgress();
          return;
        }
        const pollUrl = data.payload && data.payload.pollUrl;
        if (pollUrl) {
          // Ping the remote URL to check if the job has been completed
          this.updateDownloadProgress(pollUrl);
          return;
        }
        this.resetDownloadProgress();

        var $downloadForm = $('#downloadForm');
        $downloadForm.attr('action', 'download/' + Origin.sessionModel.get('tenantId') + '/' + Origin.editor.data.course.get('_id') + '/' + data.payload.zipName + '/download.zip');
        $downloadForm.submit();

      }.bind(this)).fail(function(jqXHR, textStatus, errorThrown) {
    validate: function (attributes, options) {
      var validationErrors = {};

      if (!attributes.password) {
        validationErrors.password = Origin.l10n.t('app.validationrequired');
      } else {
        if (attributes.password.length < 8) {
          validationErrors.password = Origin.l10n.t('app.validationlength', {length: 8});
        }
      }

      if (!attributes.confirmPassword) {
        validationErrors.confirmPassword = Origin.l10n.t('app.validationrequired');
      } else {
        if (attributes.password !== attributes.confirmPassword) {
          validationErrors.confirmPassword = Origin.l10n.t('app.validationpasswordmatch');
        }
      }

      return _.isEmpty(validationErrors)
        ? null
        : validationErrors;
    }