人人商城

display.html 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <div class="panel panel-default">
  2. <div class="panel-heading">
  3. 回复内容
  4. </div>
  5. <ul class="list-group">
  6. <li class="row list-group-item" ng-repeat="item in context.items">
  7. <div class="block">
  8. <div class="col-xs-12 col-sm-12">
  9. <textarea class="form-control content" ng-hide="item.saved" placeholder="添加要回复的内容" ng-model="item.content" rows="4" onkeyup="if (this.value.split('\n').length>4) this.rows=this.value.split('\n').length;"></textarea>
  10. <p class="form-control-static" ng-show="item.saved" ng-bind-html="item.content | nl2br"></p>
  11. </div>
  12. <div class="col-xs-12 col-sm-12 help-block">您还可以使用表情和链接。<a class="emotion-triggers" href="javascript:;" ng-init="initEmotion(this);"><i class="fa fa-github-alt"></i> 表情</a> <a class="emoji-triggers" href="javascript:;" ng-click="selectEmoji(this)" title="添加表情"><i class="fa fa-github-alt"></i> Emoji</a></div>
  13. </div>
  14. <div class="col-sm-12 text-right">
  15. <div class="btn-group">
  16. <a href="javascript:;" class="btn btn-default" ng-click="context.saveItem(item);">{{item.saved ? '编辑' : '保存'}}</a>
  17. <a href="javascript:;" class="btn btn-default" ng-click="context.removeItem(item);">删除</a>
  18. </div>
  19. </div>
  20. </li>
  21. </ul>
  22. <!-- <div class="form-group">
  23. <div class="col-sm-9">
  24. <textarea type="text" name="welcome" class="form-control" id="welcomeinput" autocomplete="off" /></textarea>
  25. <div class="help-block">设置用户添加公众帐号好友时,发送的欢迎信息。<a href="javascript:;" id="welcome"><i class="fa fa-github-alt"></i> 表情</a></div>
  26. </div>
  27. </div> -->
  28. <div class="panel-footer">
  29. <a href="javascript:;" class="btn btn-default" ng-click="context.addItem();">添加回复条目</a>
  30. <span class="help-block">添加多条回复内容时, 随机回复其中一条</span>
  31. </div>
  32. <input type="hidden" name="replies" />
  33. </div>
  34. <script>
  35. window.initReplyController = function($scope) {
  36. $scope.context = {};
  37. $scope.context.items = {php echo json_encode($replies)};
  38. if(!$.isArray($scope.context.items)) {
  39. $scope.context.items = [];
  40. }
  41. if($scope.context.items.length == 0) {
  42. $scope.context.items.push({content: ''});
  43. }
  44. $scope.context.addItem = function(){
  45. $scope.context.items.push({
  46. content: ''
  47. });
  48. };
  49. $scope.context.saveItem = function(item){
  50. item.saved = !item.saved;
  51. };
  52. $scope.context.removeItem = function(item) {
  53. require(['underscore'], function(_){
  54. $scope.context.items = _.without($scope.context.items, item);
  55. $scope.$digest();
  56. });
  57. };
  58. $scope.initEmotion = function(obj) {
  59. require(['util'], function(util){
  60. var elm = $('.emotion-triggers').eq(obj.$index);
  61. util.emotion(elm[0], elm.parent().parent().find('.content')[0], function(txt, elm, target){
  62. obj.item.content = $(target).val();
  63. $scope.$digest();
  64. });
  65. });
  66. };
  67. /*选择Emoji表情*/
  68. $scope.selectEmoji = function(obj) {
  69. require(['util'], function(util){
  70. var elm = $('.emoji-triggers').eq(obj.$index);
  71. var textbox = elm.parent().parent().find('.content')[0];
  72. util.emojiBrowser(function(emoji){
  73. var unshift = '[U+' + emoji.find("span").text() + ']';
  74. var newstart = textbox.selectionStart + unshift.length;
  75. var insertval = textbox.value.substr(0,textbox.selectionStart) + unshift + textbox.value.substring(textbox.selectionEnd);
  76. obj.item.content = insertval;
  77. $scope.$digest();
  78. });
  79. });
  80. };
  81. };
  82. window.validateReplyForm = function(form, $, _, util, $scope) {
  83. var val = [];
  84. $scope.$digest();
  85. angular.forEach($scope.context.items, function(v, k){
  86. if($.trim(v.content) != '') {
  87. this.push(v);
  88. }
  89. }, val);
  90. if(val.length == 0) {
  91. util.message('请输入有效的回复内容.');
  92. return false;
  93. }
  94. $scope.$digest();
  95. val = angular.toJson(val);
  96. $(':hidden[name=replies]').val(val);
  97. return true;
  98. };
  99. </script>