store custom texture names in closet

This commit is contained in:
printempw 2016-07-22 10:45:36 +08:00
parent 1af02caff4
commit 78d0e75d44
7 changed files with 42 additions and 80 deletions

View File

@ -44,15 +44,14 @@ class ClosetController extends BaseController
public function add()
{
if (!is_numeric(\Utils::getValue('tid', $_POST)))
throw new E('Invalid parameters.', 1);
\Utils::checkPost(['tid', 'name']);
if ($this->closet->add($_POST['tid'])) {
if ($this->closet->add($_POST['tid'], $_POST['name'])) {
$t = Texture::find($_POST['tid']);
$t->likes += 1;
$t->save();
View::json('收藏成功~', 0);
View::json('材质 '.$_POST['name'].' 收藏成功~', 0);
}
}

View File

@ -130,9 +130,12 @@ class SkinlibController extends BaseController
if (!$results->isEmpty())
{
foreach ($results as $result) {
if (($result['name'] == $t->name) && ($result['type'] == $t->type)) {
throw new E('The same file with same name has been already '.
'uploaded by others. Try another filr or change your texture name.', 1);
if ($result->type == $t->type) {
View::json([
'errno' => 0,
'msg' => '已经有人上传过这个材质了,直接添加到衣柜使用吧~',
'tid' => $result->tid
]);
}
}
}

View File

@ -49,6 +49,9 @@ class Closet
foreach ($this->textures as $texture) {
$result = Texture::find($texture['tid']);
if ($result) {
// user custom texture name
$result->name = $texture['name'];
if ($result->type == "cape") {
$this->textures_cape[] = $result;
} else {
@ -83,7 +86,7 @@ class Closet
return $this->eloquent_model->amount;
}
public function add($tid)
public function add($tid, $name)
{
foreach ($this->textures as $item) {
if ($item['tid'] == $tid)
@ -91,8 +94,9 @@ class Closet
}
$this->textures[] = array(
'tid' => $tid,
'add_at' => Utils::getTimeFormatted()
'tid' => $tid,
'name' => $name,
'add_at' => time()
);
$this->eloquent_model->amount += 1;

View File

@ -1,21 +1,38 @@
/*
* @Author: prpr
* @Date: 2016-07-19 10:46:38
* @Last Modified by: prpr
* @Last Modified time: 2016-07-21 15:59:34
* @Last Modified by: printempw
* @Last Modified time: 2016-07-22 10:25:54
*/
'use strict';
function addToCloset(tid) {
var dom = '<div class="form-group">'+
'<label for="new-name">给你的皮肤起个名字吧~</label>'+
'<input id="new-name" class="form-control" type="text" placeholder="" />'+
'</div><br />';
showModal(dom, '收藏新皮肤', 'default', 'ajaxAddToCloset('+tid+')');
return;
}
function ajaxAddToCloset(tid) {
var name = $('#new-name').val();
if (name == "") {
toastr.info('你还没有填写名称哦');
$('#name').focus(); return;
}
$.ajax({
type: "POST",
url: "../user/closet/add",
dataType: "json",
data: { 'tid' : tid },
data: { 'tid': tid, 'name': name },
success: function(json) {
if (json.errno == 0) {
toastr.success(json.msg);
$('.modal').modal('hide');
$('a[tid='+tid+']').attr('href', 'javascript:removeFromCloset('+tid+');').attr('title', '从衣柜中移除').addClass('liked');
$('#'+tid).attr('href', 'javascript:removeFromCloset('+tid+');').html('从衣柜中移除');
$('#likes').html(parseInt($('#likes').html()) + 1);
@ -145,7 +162,8 @@ function upload() {
success: function(json) {
if (json.errno == 0) {
toastr.success(json.msg);
window.setTimeout('window.location = "./show?tid='+json.tid+'"', 1000);
toastr.info('正在跳转...');
window.setTimeout('window.location = "./show?tid='+json.tid+'"', 2500);
} else {
$('#upload-button').html('确认上传').prop('disabled', '');
toastr.warning(json.msg);
@ -160,26 +178,6 @@ function upload() {
return false;
}
function saveAs(tid) {
$.ajax({
type: "POST",
url: "./save",
dataType: "json",
data: { 'name': $('#name').val(), 'type': $('#type').val(), 'public': !$('#private').prop('checked'), 'original_tid': tid },
success: function(json) {
if (json.errno == 0) {
toastr.success(json.msg);
window.setTimeout('window.location = "./show?tid='+json.tid+'"', 1000);
} else {
toastr.warning(json.msg);
}
},
error: function(json) {
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
});
}
function changePrivacy(tid) {
$.ajax({
type: "POST",

View File

@ -2,11 +2,12 @@
* @Author: printempw
*/
function showModal(msg, title, type) {
function showModal(msg, title, type, callback) {
title = title === undefined ? "Messgae" : title;
type = type === undefined ? "default" : type;
callback = callback === undefined ? 'data-dismiss="modal"' : 'onclick="'+callback+'"';
var btn_type = (type != "default") ? "btn-outline" : "btn-primary";
var dom = '<div class="modal modal-'+type+' fade in"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button><h4 class="modal-title">'+title+'</h4></div><div class="modal-body"><p>'+msg+'</p></div><div class="modal-footer"><button type="button" data-dismiss="modal" class="btn '+btn_type+'">OK</button></div></div></div></div>';
var dom = '<div class="modal modal-'+type+' fade in"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button><h4 class="modal-title">'+title+'</h4></div><div class="modal-body"><p>'+msg+'</p></div><div class="modal-footer"><button type="button" '+callback+' class="btn '+btn_type+'">OK</button></div></div></div></div>';
$(dom).modal();
}

View File

@ -108,8 +108,6 @@
<!-- App Scripts -->
<script type="text/javascript" src="./assets/dist/app.min.js"></script>
@yield('script')
<script>{{ Option::get('custom_js') }}</script>
</body>
</html>

View File

@ -33,8 +33,7 @@
</div><!-- /.box-body -->
<div class="box-footer">
@if (is_null($user))
<button disabled="disabled" class="btn btn-primary pull-right">添加至衣柜</button>
<button disabled="disabled" class="btn btn-default pull-right" style="margin-right: 10px;">另存为</button>
<button disabled="disabled" title="登录后才能使用衣柜哦" class="btn btn-primary pull-right">添加至衣柜</button>
@else
@if ($user->closet->has($texture->tid))
@ -42,7 +41,6 @@
@else
<a href="javascript:addToCloset({{ $texture->tid }});" id="{{ $texture->tid }}" class="btn btn-primary pull-right">添加至衣柜</a>
@endif
<button data-toggle="modal" data-target="#modal-save-as" class="btn btn-default pull-right" style="margin-right: 10px;">另存为</button>
@endif
<div class="btn likes" title="收藏人数" data-toggle="tooltip" data-placement="top"><i class="fa fa-heart"></i>
@ -143,45 +141,6 @@
</div><!-- /.container -->
</div><!-- /.content-wrapper -->
<div id="modal-save-as" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">另存为</h4>
</div>
<div class="modal-body">
<div class="callout callout-info">
<p>喜欢这个材质,但是上传者起的名字太蠢了?</p>
<p>或者是上传者指定的模型不是你想要的?那就另存为一份吧~</p>
<p><strong>注意:</strong>另存为会消耗积分</p>
</div>
<div class="form-group">
<label for="name">材质名称</label>
<input id="name" class="form-control" type="text" placeholder="材质名称应该小于 32 个字节且不能包含奇怪的符号" value="{{ $texture->name }}" />
</div>
<div class="form-group">
<label for="type">材质类型</label>
<select class="form-control" id="type">
<option {{ ($texture->type == "steve") ? 'selected="selected"' : '' }} value="steve">皮肤Steve 模型)</option>
<option {{ ($texture->type == "alex") ? 'selected="selected"' : '' }} value="alex">皮肤Alex 模型)</option>
<option {{ ($texture->type == "cape") ? 'selected="selected"' : '' }} value="cape">披风</option>
</select>
</div>
<label for="private" title="其他人将不会在皮肤库中看到此材质" data-placement="top" data-toggle="tooltip">
<input id="private" type="checkbox"> 设置为私密材质
</label>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
<a href="javascript:saveAs({{ $texture->tid }});" class="btn btn-primary">提交</a>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script type="text/javascript" src="../assets/libs/skin-preview/three.min.js"></script>
<script type="text/javascript" src="../assets/libs/skin-preview/three.msp.js"></script>