unserver-unify
Version:
99 lines (96 loc) • 3.29 kB
JavaScript
;
angular.module('bamboo.topic')
.service('TopicApi', function($state, ApiService, CommonService, $filter) {
var self = this;
this.get = function(url, callback) {
ApiService.get(url).then(function(result) {
if (result.data.success) {
// console.log(result);
callback(result.data.data);
} else {
console.log(result.data);
$state.go('index.404');
}
});
};
this.post = function(url, info,callback) {
ApiService.post(url, info).then(function(result) {
if (result.data.success) {
if(callback){
callback(result.data.data);
}else{
CommonService.showNoBlockInfo($filter('trans')({ eng : 'Update Successful!', chn : '更新成功'}));
$state.reload();
}
} else {
CommonService.showError($filter('trans')({ eng : 'Update Fail!', chn : '无法更新!'}));
console.log(result.data);
}
});
};
this.put = function(url, info) {
ApiService.put(url, info).then(function(result) {
if (result.data.success) {
CommonService.showNoBlockInfo($filter('trans')({ eng : 'Update Successful!', chn : '更新成功'}));
$state.reload();
} else {
CommonService.showError($filter('trans')({ eng : 'Update Fail!', chn : '无法更新!'}));
console.log(result.data);
}
});
};
this.BlogApi = function(info, callback) {
function handleData(data) {
if (!callback) {
CommonService.showNoBlockInfo($filter('trans')({ eng : 'Update Successful!', chn : '更新成功'}));
$state.reload();
} else {
callback(data);
}
}
ApiService.post('/blogs', info).then(function(result) {
if (result.data.success) {
handleData(result.data);
} else {
CommonService.showError($filter('trans')({ eng : 'Update Fail!', chn : '无法更新!'}) + result.data.error);
console.log(result);
}
});
};
this.BBSApi = function(info, callback) {
function handleData(data) {
if (!callback) {
CommonService.showNoBlockInfo($filter('trans')({ eng : 'Update Successful!', chn : '更新成功'}));
$state.reload();
} else {
callback(data);
}
}
ApiService.post('/bbstopics', info).then(function(result) {
if (result.data.success) {
handleData(result.data);
} else {
CommonService.showError($filter('trans')({ eng : 'Update Fail!', chn : '无法更新!'}) + result.data.error);
console.log(result);
}
});
};
this.GroupApi = function(info, callback) {
function handleData(data) {
if (!callback) {
CommonService.showNoBlockInfo($filter('trans')({ eng : 'Update Successful!', chn : '更新成功'}));
$state.reload();
} else {
callback(data);
}
}
ApiService.post('/grouptopic', info).then(function(result) {
if (result.data.success) {
handleData(result.data);
} else {
CommonService.showError($filter('trans')({ eng : 'Update Fail!', chn : '无法更新!'}) + result.data.error);
console.log(result);
}
});
};
});