From 78d0e75d449700465c805c3b67a982616f57a66d Mon Sep 17 00:00:00 2001 From: printempw Date: Fri, 22 Jul 2016 10:45:36 +0800 Subject: [PATCH] store custom texture names in closet --- app/Controllers/ClosetController.php | 7 ++-- app/Controllers/SkinlibController.php | 9 ++++-- app/Models/Closet.php | 10 ++++-- assets/src/js/skinlib.js | 46 +++++++++++++-------------- assets/src/js/utils.js | 5 +-- resources/views/index.tpl | 2 -- resources/views/skinlib/show.tpl | 43 +------------------------ 7 files changed, 42 insertions(+), 80 deletions(-) diff --git a/app/Controllers/ClosetController.php b/app/Controllers/ClosetController.php index 3801a8cb..07848554 100644 --- a/app/Controllers/ClosetController.php +++ b/app/Controllers/ClosetController.php @@ -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); } } diff --git a/app/Controllers/SkinlibController.php b/app/Controllers/SkinlibController.php index 03e46a24..b95f517c 100644 --- a/app/Controllers/SkinlibController.php +++ b/app/Controllers/SkinlibController.php @@ -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 + ]); } } } diff --git a/app/Models/Closet.php b/app/Models/Closet.php index 47ca98fc..3bb55767 100644 --- a/app/Models/Closet.php +++ b/app/Models/Closet.php @@ -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; diff --git a/assets/src/js/skinlib.js b/assets/src/js/skinlib.js index 0e464691..e3db3eb7 100644 --- a/assets/src/js/skinlib.js +++ b/assets/src/js/skinlib.js @@ -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 = '
'+ + ''+ + ''+ + '

'; + 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, '
'), 'Fatal Error(请联系作者)', 'danger'); - } - }); -} - function changePrivacy(tid) { $.ajax({ type: "POST", diff --git a/assets/src/js/utils.js b/assets/src/js/utils.js index 851a8914..f5fb10e7 100644 --- a/assets/src/js/utils.js +++ b/assets/src/js/utils.js @@ -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 = ''; + var dom = ''; $(dom).modal(); } diff --git a/resources/views/index.tpl b/resources/views/index.tpl index 886aa439..8a3083c0 100644 --- a/resources/views/index.tpl +++ b/resources/views/index.tpl @@ -108,8 +108,6 @@ - @yield('script') - diff --git a/resources/views/skinlib/show.tpl b/resources/views/skinlib/show.tpl index c1829f0f..5a35c052 100644 --- a/resources/views/skinlib/show.tpl +++ b/resources/views/skinlib/show.tpl @@ -33,8 +33,7 @@ - -