123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- yii.admin = (function ($) {
- var _onSearch = false;
- var pub = {
- userId: undefined,
- roleName: undefined,
- assignUrl: undefined,
- searchUrl: undefined,
- assign: function (action) {
- var params = {
- id: pub.userId,
- action: action,
- roles: $('#list-' + (action == 'assign' ? 'avaliable' : 'assigned')).val(),
- };
- $.ajax({
- url:pub.assignUrl,
- method:'post',
- data:params,
- success:function () {
- pub.searchAssignmet('avaliable', true);
- pub.searchAssignmet('assigned', true);
- },
- error:function (xhr, textStatus) {
- $('#alert-info').find('.modal-body').text(xhr.responseText);
- $('#alert-info').modal('show')
- }
- });
- },
- searchAssignmet: function (target, force) {
- if (!_onSearch || force) {
- _onSearch = true;
- var $inp = $('#search-' + target);
- setTimeout(function () {
- var data = {
- id: pub.userId,
- target: target,
- term: $inp.val(),
- };
- $.get(pub.searchUrl, data,
- function (r) {
- var $list = $('#list-' + target);
- $list.html('');
- if (r.Roles) {
- var $group = $('<optgroup label="Roles">');
- $.each(r.Roles, function () {
- $('<option>').val(this).text(this).appendTo($group);
- });
- $group.appendTo($list);
- }
- if (r.Permissions) {
- var $group = $('<optgroup label="Permissions">');
- $.each(r.Permissions, function () {
- $('<option>').val(this).text(this).appendTo($group);
- });
- $group.appendTo($list);
- }
- }).done(function () {
- _onSearch = false;
- });
- }, 500);
- }
- },
- // role & permission
- addChild: function (action) {
- var params = {
- id: pub.roleName,
- action: action,
- roles: $('#list-' + (action == 'assign' ? 'avaliable' : 'assigned')).val(),
- };
- $.ajax({
- url:pub.assignUrl,
- method:'post',
- data:params,
- success:function () {
- pub.searchRole('avaliable', true);
- pub.searchRole('assigned', true);
- },
- error:function (xhr, textStatus) {
- $('#alert-info').find('.modal-body').text(xhr.responseText);
- $('#alert-info').modal('show')
- }
- });
- },
- searchRole: function (target, force) {
- if (!_onSearch || force) {
- _onSearch = true;
- var $inp = $('#search-' + target);
- setTimeout(function () {
- var data = {
- id: pub.roleName,
- target: target,
- term: $inp.val(),
- };
- $.get(pub.searchUrl, data,
- function (r) {
- var $list = $('#list-' + target);
- $list.html('');
- if (r.Roles) {
- var $group = $('<optgroup label="Roles">');
- $.each(r.Roles, function () {
- $('<option>').val(this).text(this).appendTo($group);
- });
- $group.appendTo($list);
- }
- if (r.Permissions) {
- var $group = $('<optgroup label="Permissions">');
- $.each(r.Permissions, function () {
- $('<option>').val(this).text(this).appendTo($group);
- });
- $group.appendTo($list);
- }
- if (r.Routes) {
- var $group = $('<optgroup label="Routes">');
- $.each(r.Routes, function () {
- $('<option>').val(this).text(this).appendTo($group);
- });
- $group.appendTo($list);
- }
- }).done(function () {
- _onSearch = false;
- });
- }, 500);
- }
- },
- // route
- assignRoute: function (action) {
- var params = {
- action: action,
- routes: $('#list-' + (action == 'assign' ? 'avaliable' : 'assigned')).val(),
- };
- $.post(pub.assignUrl, params,
- function () {
- pub.searchRoute('avaliable', 0, true);
- pub.searchRoute('assigned', 0, true);
- });
- },
- searchRoute: function (target, refresh, force) {
- if (!_onSearch || force) {
- _onSearch = true;
- var $inp = $('#search-' + target);
- setTimeout(function () {
- var data = {
- target: target,
- term: $inp.val(),
- refresh: refresh,
- };
- $.get(pub.searchUrl, data,
- function (r) {
- var $list = $('#list-' + target);
- $list.html('');
- $.each(r, function (key, val) {
- var $opt = $('<option>').val(key).text(key);
- if (!val) {
- $opt.addClass('lost');
- }
- $opt.appendTo($list);
- });
- }).done(function () {
- _onSearch = false;
- });
- }, 500);
- }
- },
- initProperties: function (properties) {
- $.each(properties, function (key, val) {
- pub[key] = val;
- });
- },
- }
- return pub;
- })(jQuery)
|