init: function(){ var source = this.source; this.me = model.me; this.lang = lang; if(source.customLinks){ this.links = source.customLinks; this.custom = true; this.snipletDisplay = {}; return; } this.source.landingPage = this.snipletResource.landingPage; this.source._id = this.snipletResource._id; this.links = _.map(this.snipletResource.pages.all, (page) => { let href = '#/website/' + this.source._id + '/' + page.titleLink; if (window.location.hash.startsWith('#/preview/')) { href = '#/preview/' + this.source._id + '/' + page.titleLink; } return { title: page.title, href: href, published: page.published, index: page.index } }); console.log(this.links); this.links = _.reject(this.links, (l) => l.published === false); model.one('refresh-nav', () => this.init()); this.$apply('links') },
ClassAdmin: function(){ this.sync = function(){ if(model.me.preferences.selectedClass === undefined){ model.me.preferences.save('selectedClass', model.me.classes[0]); } oldHttp().get('/directory/class/' + model.me.preferences.selectedClass).done(function(data){ this.id = model.me.preferences.selectedClass; this.updateData(data); }.bind(this)); this.users.sync(); }; this.saveClassInfos = function(){ oldHttp().putJson('/directory/class/' + this.id, { name: this.name, level: this.level }) }; this.collection(directory.User, { sync: function(){ oldHttp().get('/directory/class/' + model.me.preferences.selectedClass + '/users', { requestName: 'loadingUsers' }).done(function(data){ data.sort(function(a, b) { return a.lastName > b.lastName?1:-1; }); this.load(data); }.bind(this)); }, removeSelection: function(){ oldHttp().postJson('/directory/user/delete', { users : _.map(this.selection(), function(user){ return user.id; }) }); Collection.prototype.removeSelection.call(this); } }); this.users.match = directory.usersMatch.bind(this.users); this.importFile = function(file, type){ var form = new FormData(); form.append(type.replace(/(\w)(\w*)/g, function(g0,g1,g2){return g1.toUpperCase() + g2.toLowerCase();}), file); form.append('classExternalId', this.externalId); oldHttp().postFile('/directory/import/' + type + '/class/' + this.id, form) .done(function(){ this.sync(); }.bind(this)) .e400(function(e){ this.sync(); var error = JSON.parse(e.responseText).message; var errWithIdx = error.split(/\s/); if (errWithIdx.length === 2) { notify.error(lang.translate(errWithIdx[0]) + errWithIdx[1]); } else { if(error.indexOf('already exists') !== -1){ notify.error('directory.import.already.exists'); } else{ notify.error(error); } } }.bind(this)); }; this.addUser = function(user){ user.saveAccount(function(){ directory.classAdmin.sync(); directory.directory.sync(); }); }; this.grabUser = function(user){ oldHttp().put('/directory/class/' + this.id + '/add/' + user.id).done(function(){ directory.classAdmin.sync(); }); }; this.blockUsers = function(value){ this.users.selection().forEach(function(user){ user.blocked = value; oldHttp().putJson('/auth/block/' + user.id, { block: value }); }); }; this.resetPasswords = function(){ this.users.selection().forEach(function(user){ oldHttp().post('/auth/sendResetPassword', { login: user.originalLogin, email: model.me.email }); }); }; model.on('preferences-updated', function(){ this.sync(); }.bind(this)); },