| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364 |
- role_parameter = {
- root : common_parameter.host + '/x_organization_assemble_control/jaxrs/role',
- list_action : null,
- list_action_parameter : null,
- first : '(0)',
- last : '(0)',
- count : 20
- };
- function role_list_reload() {
- if (role_parameter.list_action) {
- role_parameter.list_action.call(window, role_parameter.list_action_parameter);
- } else {
- role_list_next('(0)');
- }
- }
- function role_create() {
- var str = '<table border="1" width="100%">';
- str += '<tr><td colspan="2"><a href="#" id="post">post</a></td></tr>';
- str += '<tr><td>name:</td><td><input type="text" id="name" style="width:95%"/></td></tr>';
- str += '<tr><td>personList:</td><td><textarea id="personList" style="width:95%;height:200px"/></td></tr>';
- str += '<tr><td>groupList:</td><td><textarea id="groupList" style="width:95%;height:200px"/></td></tr>';
- str += '<tr><td>unique:</td><td><input type="text" id="unique" style="width:95%"/></td></tr>';
- str += '</table>';
- $('#content').html(str);
- $('#post', '#content').click(function() {
- role_post();
- });
- }
- function role_post() {
- $.ajax({
- type : 'post',
- dataType : 'json',
- url : role_parameter.root,
- contentType : 'application/json; charset=utf-8',
- data : JSON.stringify({
- name : $('#name', '#content').val(),
- personList : splitValue($('#personList', '#content').val()),
- groupList : splitValue($('#groupList', '#content').val()),
- unique : $('#unique', '#content').val()
- }),
- xhrFields : {
- 'withCredentials' : true
- },
- crossDomain : true
- }).done(function(data) {
- if (data.type == 'success') {
- role_list_reload();
- } else {
- failure(data);
- }
- });
- }
- function role_edit(id) {
- var str = '<table border="1" width="100%">';
- str += '<tr><td colspan="2"><a href="#" id="put">put</a></td></tr>';
- str += '<tr><td>id:</td><td id="id"></td></tr>';
- str += '<tr><td>sequence:</td><td id="sequence"></td></tr>';
- str += '<tr><td>name:</td><td><input type="text" id="name" style="width:95%"/></td></tr>';
- str += '<tr><td>personList:</td><td><textarea id="personList" style="width:95%;height:200px"/></td></tr>';
- str += '<tr><td>groupList:</td><td><textarea id="groupList" style="width:95%;height:200px"/></td></tr>';
- str += '<tr><td>unique:</td><td><input type="text" id="unique" style="width:95%"/></td></tr>';
- str += '</table>';
- $('#content').html(str);
- $('#put', '#content').click(function() {
- role_put(id);
- });
- $.ajax({
- type : 'get',
- dataType : 'json',
- url : role_parameter.root + '/' + id,
- xhrFields : {
- 'withCredentials' : true
- },
- crossDomain : true
- }).done(function(data) {
- if (data.type == 'success') {
- $('#id', '#content').html(data.data.id);
- $('#sequence', '#content').html(data.data.sequence);
- $('#name', '#content').val(data.data.name);
- $('#personList', '#content').html(data.data.personList.join(','));
- $('#groupList', '#content').html(data.data.groupList.join(','));
- $('#unique', '#content').val(data.data.unique);
- } else {
- failure(data);
- }
- });
- }
- function role_put(id) {
- $.ajax({
- type : 'put',
- dataType : 'json',
- url : role_parameter.root + '/' + id,
- contentType : 'application/json; charset=utf-8',
- data : JSON.stringify({
- name : $('#name', '#content').val(),
- personList : splitValue($('#personList', '#content').val()),
- groupList : splitValue($('#groupList', '#content').val()),
- unique : $('#unique', '#content').val()
- }),
- xhrFields : {
- 'withCredentials' : true
- },
- crossDomain : true
- }).done(function(data) {
- if (data.type == 'success') {
- role_list_reload();
- } else {
- failure(data);
- }
- });
- }
- function role_delete(id) {
- $.ajax({
- type : 'delete',
- dataType : 'json',
- url : role_parameter.root + '/' + id,
- xhrFields : {
- 'withCredentials' : true
- },
- crossDomain : true
- }).done(function(data) {
- if (data.type == 'success') {
- role_list_next('(0)');
- } else {
- failure(data);
- }
- });
- }
- function role_list_next(id) {
- var id = ( id ? id : role_parameter.last);
- role_parameter.list_action = role_list_next;
- role_parameter.list_action_parameter = id;
- $.ajax({
- type : 'get',
- dataType : 'json',
- url : role_parameter.root + '/list/' + id + '/next/' + role_parameter.count,
- xhrFields : {
- 'withCredentials' : true
- },
- crossDomain : true
- }).done(function(data) {
- if (data.type == 'success') {
- if (data.data.length > 0) {
- role_parameter.first = data.data[0].id;
- role_parameter.last = data.data[data.data.length - 1].id;
- } else {
- role_parameter.first = '(0)';
- }
- $('#content').html(role_list_grid(data.data));
- $('#total', '#content').html(data.count);
- role_list_init();
- } else {
- failure(data);
- }
- });
- }
- function role_list_prev(id) {
- var id = ( id ? id : role_parameter.first);
- role_parameter.list_action = role_list_prev;
- role_parameter.list_action_parameter = id;
- $.ajax({
- type : 'get',
- dataType : 'json',
- url : role_parameter.root + '/list/' + id + '/prev/' + role_parameter.count,
- xhrFields : {
- 'withCredentials' : true
- },
- crossDomain : true
- }).done(function(data) {
- if (data.type == 'success') {
- if (data.data.length > 0) {
- role_parameter.first = data.data[0].id;
- role_parameter.last = data.data[data.data.length - 1].id;
- } else {
- role_parameter.last = '(0)';
- }
- $('#content').html(role_list_grid(data.data));
- $('#total', '#content').html(data.count);
- role_list_init();
- } else {
- failure(data);
- }
- });
- }
- function role_list_grid(items) {
- var str = '<table border="1" width="100%">';
- str += '<tr><td colspan="4"> <a href="#" id="prev">prev</a> <a href="#" id="next">next</a> <span id="total">0</span></td></tr>';
- str += '<tr><th>rank</th><th>id</th><th>name</th><th>operate</th></tr>';
- $.each(items, function(index, item) {
- str += '<tr>';
- str += '<td>' + item.rank + '</td>';
- str += '<td>' + item.id + '</td>';
- str += '<td>' + item.name + '</td>';
- str += '<td>';
- str += '<a href="#" onclick="role_edit(\'' + item.id + '\')">edit</a> ';
- str += '<a href="#" onclick="role_delete(\'' + item.id + '\')">delete</a>';
- str += '</td>';
- str += '</tr>';
- });
- str += '</table>';
- return str;
- }
- function role_list_init() {
- $('#next', '#content').click(function() {
- role_list_next();
- });
- $('#prev', '#content').click(function() {
- role_list_prev();
- });
- }
- function role_query_init() {
- var str = '<table border="1" width="100%">';
- str += '<tr><td>query:</td><td><input type="text" id="query" style="width:95%"/></td></tr>';
- str += '<tr><td colspan="2"><a href="#" id="withPerson">获取人员所拥有的角色.</a></td></tr>';
- str += '<tr><td colspan="2"><a href="#" id="withGroup">获取群组所拥有的角色.</a></td></tr>';
- str += '<tr><td colspan="2"><a href="#" id="pinyinInitial">根据首字母进行查找.</a></td></tr>';
- str += '<tr><td colspan="2"><a href="#" id="like">进行模糊查找.</a></td></tr>';
- str += '<tr><td colspan="2"><a href="#" id="likePinyin">根据拼音进行查找.</a></td></tr>';
- str += '</table>';
- $('#content').html(str);
- $('#withPerson', '#content').click(function() {
- role_query_withPerson($('#query', '#content').val());
- });
- $('#withGroup', '#content').click(function() {
- role_query_withGroup($('#query', '#content').val());
- });
- $('#like', '#content').click(function() {
- role_query_like($('#query', '#content').val());
- });
- $('#pinyinInitial', '#content').click(function() {
- role_query_pinyinInitial($('#query', '#content').val());
- });
- $('#likePinyin', '#content').click(function() {
- role_query_likePinyin($('#query', '#content').val());
- });
- }
- function role_query_grid(items) {
- var str = '<table border="1" width="100%">';
- str += '<tr><th>id</th><th>name</th><th>operate</th></tr>';
- $.each(items, function(index, item) {
- str += '<tr>';
- str += '<td>' + item.id + '</td>';
- str += '<td>' + item.name + '</td>';
- str += '<td>';
- str += '<a href="#" onclick="role_edit(\'' + item.id + '\')">edit</a> ';
- str += '<a href="#" onclick="role_delete(\'' + item.id + '\')">delete</a>';
- str += '</td>';
- str += '</tr>';
- });
- str += '</table>';
- return str;
- }
- function role_query_withPerson(id) {
- role_parameter.list_action = role_query_withPerson;
- role_parameter.list_action_parameter = id;
- $.ajax({
- type : 'get',
- dataType : 'json',
- url : role_parameter.root + '/list/person/' + id,
- xhrFields : {
- 'withCredentials' : true
- },
- crossDomain : true
- }).done(function(data) {
- if (data.type == 'success') {
- $('#content').html(role_query_grid(data.data));
- } else {
- failure(data);
- }
- });
- }
- function role_query_withGroup(id) {
- role_parameter.list_action = role_query_withGroup;
- role_parameter.list_action_parameter = id;
- $.ajax({
- type : 'get',
- dataType : 'json',
- url : role_parameter.root + '/list/group/' + id,
- xhrFields : {
- 'withCredentials' : true
- },
- crossDomain : true
- }).done(function(data) {
- if (data.type == 'success') {
- $('#content').html(role_query_grid(data.data));
- } else {
- failure(data);
- }
- });
- }
- function role_query_like(key) {
- role_parameter.list_action = role_query_like;
- role_parameter.list_action_parameter = key;
- $.ajax({
- type : 'get',
- dataType : 'json',
- url : role_parameter.root + '/list/like/' + encodeURIComponent(key),
- xhrFields : {
- 'withCredentials' : true
- },
- crossDomain : true
- }).done(function(data) {
- if (data.type == 'success') {
- $('#content').html(role_query_grid(data.data));
- } else {
- failure(data);
- }
- });
- }
- function role_query_pinyinInitial(key) {
- role_parameter.list_action = role_query_pinyinInitial;
- role_parameter.list_action_parameter = key;
- $.ajax({
- type : 'get',
- dataType : 'json',
- url : role_parameter.root + '/list/pinyininitial/' + encodeURIComponent(key),
- xhrFields : {
- 'withCredentials' : true
- },
- crossDomain : true
- }).done(function(data) {
- if (data.type == 'success') {
- $('#content').html(role_query_grid(data.data));
- } else {
- failure(data);
- }
- });
- }
- function role_query_likePinyin(key) {
- role_parameter.list_action = role_query_likePinyin;
- role_parameter.list_action_parameter = key;
- $.ajax({
- type : 'get',
- dataType : 'json',
- url : role_parameter.root + '/list/like/pinyin/' + encodeURIComponent(key),
- xhrFields : {
- 'withCredentials' : true
- },
- crossDomain : true
- }).done(function(data) {
- if (data.type == 'success') {
- $('#content').html(role_query_grid(data.data));
- } else {
- failure(data);
- }
- });
- }
|